I've got the following statement in a class that creates an imageIcon:
"ImageIcon hiImage = new ImageIcon("images/hi.jpg");"
In order for this image to be loaded when the program is executed, I know that the "hi.jpg" file needs to be in a folder named "images". But where do I put that folder? Do I need to somehow zip it up in the JAR file for my finished program? I'm a little confused about where the JVM is going to look for the "images" folder....
Hi Landon Blake, What the JVM does is it goes to the default directory in search of the source files and images etc. The dafult directory can be the JAVA_HOME\bin or the folder that you have mentioned when setting the CLASS path. In your case the image folder should reside inside this default folder. Hope I was able to clear your doubt. Just reply if you need any more clarifications....
SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
posted 14 years ago
First, I want to thank you for your response. It did answer my original question. However, it did raise another question.
If I package up my program into a jar file, "test.jar", and I want a user on another computer to execute the jar file and run my program, where do I place the images so that they display properly in the Swing GUI? Must my program install a directory on the users file system that is in the classpath? Isn't there a way to "wrap up" the images in the jar file so the JVM looks for the files in the jar itsel or in the same directory that the jar is in? (Or perhaps I can package the jar and the directory for the images in a zip file. When the user unzips the file, the directory with the images and the jar file is extracted to the same location on the file system. Would this work?)
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?