wood burning stoves 2.0*
The moose likes Java in General and the fly likes using gif file in application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "using gif file in application" Watch "using gif file in application" New topic
Author

using gif file in application

jeff krystyan
Greenhorn

Joined: Apr 02, 2012
Posts: 9
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: 18541
    
    8

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: 38519
    
  23
And welcome to the Ranch
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19685
    
  20

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
jeff krystyan
Greenhorn

Joined: Apr 02, 2012
Posts: 9
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using gif file in application