This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 38045
    
  22
And welcome to the Ranch
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

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
 
Similar Threads
i have problem with Accessing files
Image constructor says it's NULL
writing jpg/gif to rtf
Getting the Key from a properties file
How to create JAR files