aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes What's the best way to getImage()? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "What Watch "What New topic
Author

What's the best way to getImage()?

Timothy Stone
Ranch Hand

Joined: Aug 01, 2001
Posts: 71
I'm having some trouble figuring out what is the best, most reliable, cross-platform method of getting a handle on an Image object from the local filesystem.
I'm noticing some confusing methods in the API but have worked around them and have something working on a Wintel platform but I want to make it as platform-agnostic as possible.
Two (2) methods exist in the Toolkit API:
public abstract Image getImage( java.lang.String ) and
public abstract Image getImage( java.net.URL )
I've noticed in my development wanderings that the String object passed is not noted as being relative to the class/package or to "root". I'm saying this because, given a directory "images" under the package, the String "images/imagex.gif" will return null, but the String "/images/imagex.gif" works, as does the String "C:/.../images/imagex.gif". Where is the proper String path documented?
My second dilemma is which method is better? I saw a Swing example using:
ClassLoader.getSystemResource( java.lang.String ) where the String object passed is a relative path to the image, i.e. "images/imagex.gif". The static method getSystemResource returns a URL object from relative to the CLASSPATH defined on the system. This seems to be very platform agnostic and preferred in cross platform development, but I have not found any notes that this is good/bad/ugly. Can anyone help this conflicted developer?
Thanks a ton.
Tim

Timothy Stone, MIT, SCJP
http://www.petmystone.com/
"This Satan's drink [coffee] is so delicious, we shall cheat Satan and baptize it." --Pope Clement the VIII (1592-1605)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: What's the best way to getImage()?
 
Similar Threads
Applet, How to get the image displayed PLEASE HELP
Cant load images from my jar
Randomly displaying images from a directory with JavaScript?
A few problems with the Custom Cursor
Copy Picture (Image)