facing some difficulties in the "IconImage"?
I want to add IconImage to a buttom and a label by using the following command:
public ImageIcon image1=new ImageIcon("D:/Java/WebSearchProject/c.gif");
JLabel jLabel1 = new JLabel(image2);
The problem is If I compile this application, the picture c.gif will not package in my program, when c.gif is deleted from "D:/Java/WebSearchProject/c.gif" , It will not be displayed in my program too. See there are some example by using "WebSearchProject/c.gif", they do not need to use the whole path, How can I do this if I want my program contain this IconImage c.gif whereever I go it is runalbe, where should I put this picture file or how I can solve this problem?
Thank you very much!!!
[715 byte] By [
brofa] at [2007-10-3 8:26:21]

If I package it in the program, do I still need to write the following command: public ImageIcon image1=new ImageIcon("D:/Java/WebSearchProject/c.gif");the most important is "D:/Java/WebSearchProject/c.gif" ,
brofa at 2007-7-15 3:32:44 >

> If I package it in the program, do I still need to
> write the following command:
> public ImageIcon image1=new
> ImageIcon("D:/Java/WebSearchProject/c.gif");
> he most important is "D:/Java/WebSearchProject/c.gif"
> ,
Maybe I don't understand your question but you will still need to create the image icon in the code.
If you are asking about your file path then yes, it will change to where ever you put the file.
Also check out this method:
class.getClassLoader().getResource(path)
As far as I know the picture should be packaged in the .jar program file, but it is useless, because the path="D:/Java/GUIprogram/src/guiprogram/d.gif"then it has nothing to with the d.gif in .jar package, I am so confusing now!!! What should I do?Thank you very much!!!
brofa at 2007-7-15 3:32:44 >

> As far as I know the picture should be packaged in
> the .jar program file, but it is useless, because the
> path="D:/Java/GUIprogram/src/guiprogram/d.gif"
> then it has nothing to with the d.gif in .jar
> package, I am so confusing now!!! What should I
> do?
>
> Thank you very much!!!
If you put it in the jar then your path will change:
Check out this method:
class.getClassLoader().getResource(path)
I did it !!!! Thank you very much!!!
Infact there are two ways to give the path:
1. "D:/Java/GUIprogram/src/guiprogram/d.gif" (real path)
2.guiprogram.CalFrame.class.getResource("d.gif") (indirect path)
if we use the second one, after compile, it can be run everywhere without limitation.
Again thank you very much for your help.
brofa at 2007-7-15 3:32:44 >
