Java图形界面(2)按钮类

 1 import javax.swing.*;
 2 public class Test2 extends JFrame {
 3 
 4     public static void main(String[] args) {
 5 
 6         Test2 jfrm=new Test2();
 7         ImageIcon ic=new ImageIcon("灯笼.png");
 8         JButton btn=new JButton("灯笼",ic);
 9         
10         jfrm.setLayout(null);
11         jfrm.setSize(250,180);
12         jfrm.setTitle("按钮类窗口");
13         btn.setBounds(50, 45, 150, 60);
14         btn.setToolTipText("我是按钮");
15         
16         jfrm.add(btn);
17         jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
18         jfrm.setVisible(true);
19     }
20 
21 }

原文地址:https://www.cnblogs.com/ljydbk/p/14790990.html