• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using gif file in application

 
jeff krystyan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 20980
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jeff krystyan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic