I answered my question myself by trying it. While building a standalone program it apparently doesn't matter if I use a JApplet class for this issue. Anyway, it didn't help, as I still have the same problem. However, it did prove what I already knew, it cannot find the file. I am guessing that the crux of the problem is that I am not specifying the path correctly. The 'img' sub-directory is in the same directory as the .java files containing all the classes. I even tried moving the image file to the same directory and referencing it without the 'img/' to no avail. Where is the darn thing supposed to be relative to the class definition? TIA.
Thanks but I found using your Applet method opens a default Applet window which I don't want. I couldn't get that to work either in any case. It kept throwing an InstantiationException. The main problem at this point is that I don't know how to generate a useful error message explaining why the file is not found or loaded. I even tried an absolute path as suggested in another example. That example was quite simple and had me do this:
There is no exception thrown so something legitimate is being put into 'logo' but whatever it is, is not being displayed in the JLabel.
> Thanks but I found using your Applet method opens a default Applet window which I don't want.
I may have led you astray. In your first post I saw this
and assumed you were trying to display an image in an applet, so I posted the applet example with getCodeBase()
Probably best now to post a compilable/runnable example, so we can run it and see if it works for us (or not).
not a lot of code, just enough to display an image in a JLabel in a JFrame or whatever container you're using
Thanks for the help. I started out writing a couple of simple applets and then started on this standalone program. I didn't bother to change the directory and just started a new project in the same one. Thats why it wound up with that directory in the path.
Anyway, I'm trying to produce a splash screen and the class definition is not that big so this should give you enough.
I'm assuming you can use any jpg and don't need the one I have.
after adding the imports and a main(), also removing all references to the class CountDownLatch,
the code compiled, ran and displayed my images fine (.gif and .jpg).
The images were in the same folder as the .java and .class files
also, there is a java.awt.SplashScreen class which might make it easier for you.
I am going down to the lab. Do NOT let anyone in. Not even this tiny ad: