简体   繁体   中英

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 anyone 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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM