• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Toolbar Question

 
Terry McKee
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was planning on putting in a toolbar in my gui, but I am having a problem accessing my jar of graphic files. All of the examples on Sun's site use applets so I am hoping that someone here can help. If I have my jar file in directory C:\developer\images\Images.jar. How can I access, say, Save.jpg that is in Images.jar?

Finally, if I have Images.jar contained in Client.jar, how can I access Save.jpg in Images.jar?
This would be extremely helpful!
 
Ashley Tate
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Terry,
First of all you might want to reconsider putting your images in a separate jar file. Is this really necessary? There might be some gee whiz factor in being able to change the look of the application by swapping in a new images.jar file, but ask yourself if this is a real requirement.
Here is sample code for loading an image outside of an Applet:
============================================================
import java.awt.Toolkit;
import java.awt.Image;
import java.net.URL;
...
Toolkit toolkit = Toolkit.getDefaultToolkit();
URL imageURL = this.getClass().getResource("/images/myimage.gif");
Image image = toolkit.createImage(imageURL);
============================================================
Keep in mind that the path you use to access the image file ('/images/myimage.gif' in this example) is relative to the classpath you defined when you started the JVM. So, if you defined your classpath to be:
classpath=C:\developer\images\Images.jar;C:\developer\images\client.jar
and your image was in one of these jar files at '/images/myimage.gif', then the code sample above would load your image.
Ashley Tate

[This message has been edited by Ashley Tate (edited November 10, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic