Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What's the best way to getImage()?

 
Timothy Stone
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic