Gui中间的Window监听关闭操作
1.GUI关闭的 监听操作
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class Text {
public static void main(String[] args) {
Frame frame = new Frame("大家好");//标题
Panel panel = new Panel(null);//面板
frame.setLayout(null);//布局
frame.setBounds(300,400,500,600);设置总体面板
frame.setBackground(Color.red);
panel.setBounds(100,200,400,500);中间部分的布局
panel.setBackground(Color.BLUE);
frame.add(panel);
frame.setVisible(true);//将软件可视化
//引用Window监听
frame.addWindowListener(new WindowListener() {
@Override
public void windowOpened(WindowEvent e) {
}
@Override
public void windowClosing(WindowEvent e) {
//Window关闭功能
System.exit(0);
}
@Override
public void windowClosed(WindowEvent e) {
}
@Override
public void windowIconified(WindowEvent e) {
}
@Override
public void windowDeiconified(WindowEvent e) {
}
@Override
public void windowActivated(WindowEvent e) {
}
@Override
public void windowDeactivated(WindowEvent e) {
}
});
}
}
2.测试
- 可以被X掉
- 如果没有windowClosing的功能就不会被X掉
3.来源
1.狂神视频学习
2.如果错误请指出改正
3.本人刚刚入门有些知识不是很专业望理解