package com.xiaocong.listener; import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; public class Test { public static void main(String[] args) { Frame frame = new Frame("肖"); Panel panel = new Panel(null); frame.setLayout(null); frame.setBounds(300,300,500,500); frame.setBackground(new Color(0,0,255)); panel.setBounds(50,50,300,300); panel.setBackground(new Color(0,255,0)); frame.add(panel); frame.setVisible(true); //监听事件,监听关闭事件 frame.addWindowListener(new WindowListener() { public void windowOpened(WindowEvent e) { System.out.println("打开"); } public void windowClosing(WindowEvent e) { System.out.println("关闭ing"); System.exit(0); } public void windowClosed(WindowEvent e) { System.out.println("关闭ed"); } public void windowIconified(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowActivated(WindowEvent e) { System.out.println("激活"); } public void windowDeactivated(WindowEvent e) { System.out.println("未激活"); } }); // frame.addWindowListener(new WindowAdapter() { // @Override // public void windowClosing(WindowEvent e) { // super.windowClosing(e); // } // }); } }
GUI中的监听器
最新推荐文章于 2023-06-08 17:06:12 发布