This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Displaying Images that are insigned Applet

 
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.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • 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
 
look! it's a bird! it's a plane! It's .... a teeny tiny ad
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!