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);
}
精彩评论