Panel面板,并解决关闭窗口
package com.tai;
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(300,300,500,500);
frame.setBackground(Color.green);
panel.setBounds(50,50,400,400);
panel.setBackground(Color.red);
frame.add(panel);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}