why the picture can't show?
i just want to show a picture as a JButton on JFrame,the picture's path is the path of the project,bu when the program run ,i can see the frame,bu can't see the picture,why ?
import java.awt.*;
import javax.swing.*;
publicclass UseImageextends JFrame{
JButton bn;
ImageIcon icon;
public UseImage(){
this.setSize(400, 300);
this.setLocation(200, 150);
icon =new ImageIcon("88.gif");
bn =new JButton("picture",icon);
//bn.setIcon(icon);
this.getContentPane().add(bn);
this.getContentPane().
setVisible(true);
}
publicstaticvoid main(String args[]){
new UseImage();
}
}
Message was edited by:
suncs2001
Message was edited by:
suncs2001
[1456 byte] By [
suncs2001a] at [2007-11-27 4:27:46]

# 1
import java.awt.*;
import javax.swing.*;
public class UseImageRx extends JFrame {
JButton bn;
public UseImageRx() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setSize(400, 300);
this.setLocation(200, 150);
// Works okay. Images folder is in the current directory.
ImageIcon icon = new ImageIcon(//"88.gif");
"images/geek--.gif");
// Another option - have class loader find it (on class path).
java.net.URL url = getClass().getResource("images/geek--.gif");
// Let's see if the class loader found it.
System.out.println("url = " +
((url == null) ? url : url.getPath()));
//ImageIcon icon = new ImageIcon(url);
// Check on the loading operation.
String s = "";
int status = icon.getImageLoadStatus();
if((status & MediaTracker.ABORTED) == MediaTracker.ABORTED)
s += "ABORTED ";
if((status & MediaTracker.ERRORED) == MediaTracker.ERRORED)
s += "ERRORED ";
if((status & MediaTracker.COMPLETE) == MediaTracker.COMPLETE)
s += "COMPLETE";
System.out.println("status = " + s);
bn = new JButton("picture",icon);
JPanel panel = new JPanel();
panel.add(bn);
this.getContentPane().add(panel);
setVisible(true);
}
public static void main(String args[]) {
new UseImageRx();
}
}
Another possibility (besides path problems) is that the image data is corrupted or
unreadable. Try different images.