开发者

image in a brand new jframe?

I am simply looking for a class that will create a new jframe displaying the image "rules.jpg" which is found in the src folder of my project.

edit: i worked out how to do this just there, but the image STILL wont display when i export it to a jar, does anyo开发者_如何学JAVAne have any tips?


To load the image from a jar, you will need to access it differently. There is nice Swing tutorial for doing exactly that:

http://download.oracle.com/javase/tutorial/uiswing/components/icon.html#getresource

Here is some relevant code form the tutorial:

java.net.URL imageURL = myDemo.class.getResource("images/myImage.gif");
...
if (imageURL != null) {
    ImageIcon icon = new ImageIcon(imageURL);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜