Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying Images that are insigned Applet

 
Jeff Holmes
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeff Holmes
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic