不知道为什么我的小程序没有显示。它显示在eclipse中,但是当我编译一个jar并从windows cmd运行它时,它不显示。输出System.out.println
在整个代码中都有效,并出现在命令行上。我做错了什么,是编译可执行jar还是带有清单的东西?我需要在 jar 或 windows 中获得某种权限吗?我应该使用诸如属性文件而不是参数之类的东西吗?第一次使用 jars、applet、jgraph。我使用的命令是 java -jar test.jar c:/test.xml
main.java
public static void main(String[] args) {
File file = new File(args[0]);
GraphMain(file).init();
System.out.println("The file path is " + file);
}
GraphMain.java
public class GraphMain extends JApplet {
//Stuff
File DRUGBANK_DIR;
public GraphMain(File DrugBankFile)
{
DRUGBANK_DIR = DrugBankFile;
}
public void init()
{
// a lot stuff
// create a JGraphT graph
UndirectedGraph<String, DefaultEdge> g =
new ListenableUndirectedGraph<String, DefaultEdge>( DefaultEdge.class );
// create a visualization using JGraph, via an adapter
m_jgAdapter = new JGraphModelAdapter<String, DefaultEdge>( g );
JGraph jgraph = new JGraph( m_jgAdapter );
adjustDisplaySettings( jgraph );
getContentPane( ).add( jgraph );
resize( DEFAULT_SIZE );
//stuff
positionVertices(vertices0, vertices1);
}
private void positionVertices(List<String> vertices0, List<String> vertices1)
{
int dy0 = DEFAULT_SIZE.height / (vertices0.size() + 5);
int y0 = dy0;
for (String v0 : vertices0)
{
positionVertexAt(v0, 100, y0);
y0+=dy0;
}
int dy1 = DEFAULT_SIZE.height / (vertices1.size() + 2);
int y1 = dy1;
for (String v1 : vertices1)
{
positionVertexAt(v1, 700, y1);
y1+=dy1;
}
}
private void adjustDisplaySettings( JGraph jg ) {
jg.setPreferredSize( DEFAULT_SIZE );
Color c = DEFAULT_BG_COLOR;
String colorStr = null;
try {
colorStr = getParameter( "bgcolor" );
}
catch( Exception e ) {}
if( colorStr != null ) {
c = Color.decode( colorStr );
}
jg.setBackground( c );
}
private void positionVertexAt( Object vertex, int x, int y ) {
DefaultGraphCell cell = m_jgAdapter.getVertexCell( vertex );
Map<?, ?> attr = cell.getAttributes( );
Rectangle2D b = GraphConstants.getBounds( attr );
GraphConstants.setBounds( attr, new Rectangle2D.Double( x, y, b.getWidth(), b.getHeight() ) );
Map<DefaultGraphCell, Map<?, ?>> cellAttr = new HashMap<DefaultGraphCell, Map<?, ?>>( );
cellAttr.put( cell, attr );
m_jgAdapter.edit( cellAttr, null, null, null);
}
}