I have an applet that has some buttons that use .jpg's for display on the buttons. Works great locally. I then create a JAR file with the class files and the images in the jar. The images aren't in any sub-directories, just the files in the root of the jar. The line I use in the code is ImageIcon = new ImageIcon("pos.jpg"); And there is a pos.jpg in the JAR, not under any subdirectories. But when I sign applet, place on web-server, the image is not found. So I placed a new File in the applet, and placed some output that states if pos.jpg is a file or not. Doesn't find it, so it reports not a file. Can some please explain to me how the JAR's work with applets. The applet is launched in the web page with parameter for CODE="package.name.class" ARCHIVE="pos.jar" which works fine. Just can't access the files inside the JAR. Thanks for the help.
Jeff, To read an image from a jar file, do this in your code:
This is because the image is zipped inside the .jar file, and can only be accessed as a "resource"... HTH, -Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
posted 18 years ago
Thanks Nathan. This works great. One other thing that I missed when using resources(Never had used any previously, Mostly servlet programing) that the resource has to be in the same directory or in a subdirectory of the class. Works great and I really appreciate the example. Thanks, Jeff
look! it's a bird! it's a plane! It's .... a teeny tiny ad