JButton上为何不能显示图标
下面是我的代码:importjavax.swing.*;publicclassMyPanelextendsJPanel{publicMyPanel(){ImageIcon...
下面是我的代码:
import javax.swing.*;
public class MyPanel extends JPanel {
public MyPanel(){
ImageIcon icon = new ImageIcon("image/lost.bmp");
JButton bt=new JButton(icon);
add(bt);
}
}
import java.awt.event.*;
import javax.swing.JFrame;
public class MyFrame extends JFrame {
public MyFrame(){
setSize(300,300);
setLocation(300,300);
MyPanel bb = new MyPanel();
getContentPane().add(bb);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
}
public class ButtonTest {
/**
* @param args
*/
public static void main(String[] args) {
MyFrame frame = new MyFrame();
frame.setVisible(true);
// TODO 自动生成方法存根
}
} 展开
import javax.swing.*;
public class MyPanel extends JPanel {
public MyPanel(){
ImageIcon icon = new ImageIcon("image/lost.bmp");
JButton bt=new JButton(icon);
add(bt);
}
}
import java.awt.event.*;
import javax.swing.JFrame;
public class MyFrame extends JFrame {
public MyFrame(){
setSize(300,300);
setLocation(300,300);
MyPanel bb = new MyPanel();
getContentPane().add(bb);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
}
public class ButtonTest {
/**
* @param args
*/
public static void main(String[] args) {
MyFrame frame = new MyFrame();
frame.setVisible(true);
// TODO 自动生成方法存根
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询