1 //Panel 可以看成是一个空间,但是不能单独存在
2 public class TestPanel {
3 public static void main(String[] args) {
4 Frame frame = new Frame();
5 Panel panel = new Panel();
6 //设置布局
7 frame.setLayout(null);
8
9 //坐标
10 frame.setBounds(300,300,500,500);
11 frame.setBackground(new Color(1,1,1));
12
13 //panel设置坐标
14 panel.setBounds(50,50,400,400);
15 panel.setBackground(new Color(71, 196, 214));
16
17 //frame.add(panel)
18 frame.add(panel);
19
20 //设置可见性
21 frame.setVisible(true);
22
23 //监听事件,监听窗口关闭实践 System.exit(0)
24 //适配器模式
25 frame.addWindowListener(new WindowAdapter() {
26 //窗口关闭要做的事
27 @Override
28 public void windowClosing(WindowEvent e) {
29 System.exit(0);
30 }
31 });
32
33 }
34 }
