1、点击时产生相应的动作事件
方法摘要 | |
---|---|
void |
windowActivated(WindowEvent e) 将 Window 设置为活动 Window 时调用。 |
void |
windowClosed(WindowEvent e)
因对窗口调用 dispose 而将其关闭时调用。 |
void |
windowClosing(WindowEvent e)
用户试图从窗口的系统菜单中关闭窗口时调用。 |
void |
windowDeactivated(WindowEvent e)
当 Window 不再是活动 Window 时调用。 |
void |
windowDeiconified(WindowEvent e)
窗口从最小化状态变为正常状态时调用。 |
void |
windowIconified(WindowEvent e)
窗口从正常状态变为最小化状态时调用。 |
void |
windowOpened(WindowEvent e)
窗口首次变为可见时调用。 |
1 public class TestWindowEvent extends Frame 2 { 3 public static void main(String[] args) { 4 TestWindowEvent frame = new TestWindowEvent(); 5 frame.setSize(500, 300); 6 frame.addWindowListener(new MyWindowListener()); 7 frame.setVisible(true); 8 } 9 } 10 class MyWindowListener implements WindowListener 11 { 12 @Override 13 public void windowOpened(WindowEvent e) { 14 } 15 //点击窗口上面的叉叉的时候调用 16 @Override 17 public void windowClosing(WindowEvent e) { 18 System.out.println("world"); 19 //程序退出的方法 20 System.exit(0); 21 } 22 //调用dispose方法的时候 23 @Override 24 public void windowClosed(WindowEvent e) 25 { 26 System.out.println("hello");//掌握这一个就好了 27 } 28 @Override 29 public void windowIconified(WindowEvent e) { 30 } 31 @Override 32 public void windowDeiconified(WindowEvent e) { 33 } 34 @Override 35 public void windowDeactivated(WindowEvent e) { 36 } 37 @Override 38 public void windowActivated(WindowEvent e) { 39 } 40 }
来源:https://www.cnblogs.com/cyg-06/p/5954807.html