package com.jia.lesson;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class TestPanel {
public static void main(String[] args) {
Frame frame = new Frame();
Panel panel = new Panel();
//设置布局
frame.setLayout(null);
//设置坐标和背景颜色
frame.setBounds(200, 200, 300, 300);
frame.setBackground(new Color(124, 190, 193));
//panel设置坐标,相对于frame
panel.setBounds(100, 100, 200, 200);
panel.setBackground(new Color(193, 88, 36));
//让面板在布局上显示
frame.add(panel);
//设置可见性
frame.setVisible(true);
//监听事件,监听窗口关闭事件 System.exit(0)
//适配器模式:
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}