-
Image File Location
Hi.
I'm sorry if this is in the wrong section. It deals with an Applet (which theres a separate section for), but is also incredibly basic. Since even most of the post titles in the "New to Java" section went over my head (lol), I figured I was better off posting in here.
I recently taught myself some basics over the summer for a course I'm going to take this fall. In doing so, I tried making some applets containing images. I tried this several times using a line similar to below.
Image img = getImage( getCodeBase(), "Filename");
This didn't exactly work out for me; I think the problem is that the program can't find the file I'm referencing. The book I read didn't give too much info on where to save the actual image file I was referencing, or what getCodeBase did
What's the best way to bring in an image file like this?
Thanks for your time.
-
When in doubt, print it out:
Code:
System.out.println(getCodeBase().toString());
That should give you some idea of where getCodeBase is pointing. Now you can look at where your file is and adjust the path appropriately.
Much luck to ya.
PS: getImage appears to be the proper code for you to use here. Just keep in mind to check out what the code base is, where the file is, and how they relate to one another.
-
Thanks. Haha I'm a bit embarassed I didn't think of such a simple solution, but it worked well.