On Thu, 5 Jul 2001, Daniel Moscoso wrote:
> You just have to pass the file as an URL:
>
> URL textureURL = new URL("file:./background.jpg");
> TextureLoader loader = new TextureLoader(textureURL, this);
Another useful way to do it is to use getClass().getResource() for
instance you could do:
URL textureURL = getClass().getResource("background.jpg");
TextureLoader loader = new TextureLoader(textureURL, this);
The usefulness of this is this method will work transparently within a
jar. So if you have some images that you know you will be distributing
with your application you can just package them in the jar and your user
will just have one download.
A word of warning. If you use packages then getResource() will be relative
to the location of the class in the package hierarchy. For instance is I
have:
org.himinbi.app.TestApp (stored in org/himinbi/app of course)
and I use getClass().getResource("background.jpg") then it is going to try
to open org/himinbi/app/background.jpg.
--
Imagine you have an app called TestApp in org/himinbi/app and you want to
open images/background.jpg. All of the files are packed in a jar you made
like:
jar cvf TestApp.jar org images
If you are running without the jar you could get the file using:
getResource("../../../images/background.jpg")
You can't do relative paths in jars though so this won't work. In a jar
though you can use absolute paths and they will be relative to the jars
structure so you could use:
getResource("/images/background.jpg")
But this wouldn't work in an unpacked jar unless you happened to be coding
at the root of your filesystem which is unlikely.
For you situation it probably won't matter because it didn't sound like
you were using packages. If everything is relative to the same directory
then:
getResource("background.jpg")
will work for both. Does anyone know a way to write one path that will
work both places? I guess you could get a url for the current class and
see if it begins with jar: or not and make your path accordingly but that
seems like a bit kludgy to me.
Will
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".