您的位置:首页 > 其它

How to run the Jar well?

2007-01-09 23:59 411 查看
This problem has puzzled me for nearly three days...

As I don't know even this kind of thing would happen at the first place...

About how to display the picture, if i write the related codes like this:

aquariumImage = Toolkit.getDefaultToolkit().getImage("bubbles.gif");

it can be run well in the eclipse but in the jar.

so I change it into this by adding URL :

URL address = getClass().getResource("bubbles.gif");
aquariumImage = Toolkit.getDefaultToolkit().getImage(address);

it then works perfectly.


import java.awt.*;


import java.awt.event.WindowAdapter;


import java.awt.event.WindowEvent;


import java.net.URL;






public class Test extends Frame




...{




private static final long serialVersionUID = 1L;




static Image aquariumImage;




public Test()




...{


addWindowListener(new WindowAdapter()




...{


public void windowClosing(WindowEvent e)




...{


dispose();


System.exit(0);


}


});


}




public static void main(String[] args)




...{


Test test = new Test();


test.go();


test.setSize(600, 435);


test.setVisible(true);




Graphics g = test.getGraphics();


while (!g.drawImage(aquariumImage, 0, 0, test));


}




public void go()




...{


URL address = getClass().getResource("bubbles.gif");


aquariumImage = Toolkit.getDefaultToolkit().getImage(address);


}


}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: