aspose file tools*
The moose likes Beginning Java and the fly likes URL - Placement of Image Files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "URL - Placement of Image Files" Watch "URL - Placement of Image Files" New topic
Author

URL - Placement of Image Files

Landon Blake
Ranch Hand

Joined: Oct 15, 2004
Posts: 44
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....

Thanks for the help,

Landon
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
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)
Landon Blake
Ranch Hand

Joined: Oct 15, 2004
Posts: 44
Ransika,

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?)

Thanks,

Landon
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URL - Placement of Image Files