public class Imgtest extends JFrame{
Imgtest(){
super("图片测试窗口");
this.setSize(500,500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon img = new ImageIcon("G://eclipse-work//jswing//imgs//test1.jpg");//创建图片组件,指定图片地址
JButton imgButton = new JButton(img);//将图片组建作为参数传给JButton
JPanel panel = new JPanel();
panel.add(imgButton );
this.setContentPane(panel);
}
public static void main(String[] args) {
Imgtest i = new Imgtest();
i.show();
}
}