Click to See Complete Forum and Search --> : Including Gif files in Java
Manik
September 22nd, 2000, 07:03 AM
Hi,
I want to create an ImageIcon from a GIF file. I want to include this Gif file in my project so that i don't have to be dependant on an absolute path each time my program runs... since this program would be running in a different PC too...
Is there a way where in my gif file becomes part of my project and is picked up straight from there...
Regards,
Manik
dogbear
September 22nd, 2000, 09:01 AM
Manik,
I've done extensive research and conferring with experts in the field about your particular issue and I have come up with the following answer:
No.
If you want your GIF to be part of your project, then keep it in the same directory as your CLASS files OR keep EVERYTHING in a jar file.
Otherwise, you could go through the trouble of creating a class which holds the bit data of the GIF in a hard-coded fashion and I certainly would not waste my time doing that.
Barring some complete misunderstanding on my part, I hope this helps.
Regards,
dogBear
PS Please Rate this Response!!!!
Manik
September 22nd, 2000, 12:47 PM
Hi dogBear,
I have copied the gif file in my class directory, but how do i call it without specifying the entire path of the file...
eg. new ImageIcon("c:\\class\\xyz.gif");
instead i want to do something like
new ImageIcon("xyz.gif")...
this is not working.... is there any solution to this...
regards,
Manik
Phill
September 22nd, 2000, 08:10 PM
Hi
Your problem is happening because the current
directory isnt where your class files are,
but it is where you compliled the source files.
One way to solve your problem is to programmatically browse through all of your directories on the system
untill you locate the directory where you
placed the file. Then once in the directory
locate the image file then make a reference
to it. ie:
public static File imagefile = new File("your.gif");
then you can reference this from anywhere
in the program by importing the class and
calling
//where "ClassName" is the name of the class where your image reference is.
JLabel jl = new JLabel(new ImageIcon(ClassName.imagefile.getAbsolutePath()));
You can also get that directory name by calling
ClassName.imagefile.getParent();//returns a String
Hope this is clear.
If you need help with this you can
Email me @
kashmir@zip.com.au
Good Luck
Phill
Manik
September 25th, 2000, 05:10 AM
Thanks a lot Phill...
Ur solution was of great help...
Regards,
Manik
Phill
September 25th, 2000, 05:20 AM
Your welcome !
Phill.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.