package 狂神说.p3;
import java.awt.*;
import java.awt.event.WindowListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
public class TestPanel {
public static <windowAdapter> void main(String[] args) {
Frame frame=new Frame("我的第二个Frame窗口");
Panel panel=new Panel();
//设置布局;
frame.setLayout(null);
//坐标
frame.setBounds(300,300,500,500);
panel.setBounds(50,50,300,300);
//背景色
frame.setBackground(new Color(32, 187, 203));
panel.setBackground(new Color(100,100,100));
//添加panel面板到Frame窗口
frame.add(panel);
//设置可见性
frame.setVisible(true);
//监听事件,监听窗口关闭事件 System.exit(0);
//适配器模式
frame.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
在Frame窗口中添加Panel窗口