| Author |
using gif file in application
|
jeff krystyan
Greenhorn
Joined: Apr 02, 2012
Posts: 8
|
|
Hey everybody,
I'm new to java. I want an app to open a gif file. I'm trying to use the ImageIcon class. My question is...where does the gif file need to be so the the program can find it?
Please assume I know nothing. The gif file is in My Pictures folder right now but I'm not sure where it needs to be.
Thanks,
jjungle
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
|
It needs to be somewhere where the program can access it. Shall we stipulate that you don't mind that it has to be on the same computer where the program is running, for now? Then it can be anywhere on that computer. Just provide the full path to the file in your ImageIcon constructor call.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
And welcome to the Ranch
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
Paul Clapham wrote:It needs to be somewhere where the program can access it. Shall we stipulate that you don't mind that it has to be on the same computer where the program is running, for now? Then it can be anywhere on that computer. Just provide the full path to the file in your ImageIcon constructor call.
Another alternative is to put the image in a folder that's part of the class path (for example the same folder your class file will end up), then use getClass().getResource(...) to get a URL which you can use to create an ImageIcon. The advantage of this is, you can package your GIF file inside your JAR file and it will be available no matter on which PC you deploy the JAR file.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
jeff krystyan
Greenhorn
Joined: Apr 02, 2012
Posts: 8
|
|
|
thank you all for the comments. Sorry about the late thanks. I had figured it out and just kept working without checking back in. Thanks again!
|
 |
 |
|
|
subject: using gif file in application
|
|
|