Java捕获其他窗口事件


Java捕获其他窗口事件:

  1. package com.han;  
  2.   
  3. import java.awt.event.WindowEvent;  
  4. import java.awt.event.WindowListener;  
  5.   
  6. import javax.swing.JFrame;  
  7.   
  8. /** 
  9.  * 捕获其他窗口事件 
  10.  * @author HAN 
  11.  * 
  12.  */  
  13. public class WindowEvent_3 extends JFrame {  
  14.   
  15.     /** 
  16.      *  
  17.      */  
  18.     private static final long serialVersionUID = 9040264048222645786L;  
  19.   
  20.     public WindowEvent_3() {  
  21.         // TODO Auto-generated constructor stub   
  22.         addWindowListener(new WindowListener() {  
  23.   
  24.             @Override  
  25.             public void windowOpened(WindowEvent e) {  
  26.                 // TODO Auto-generated method stub   
  27.                 System.out.println("窗口被打开!");  
  28.             }  
  29.   
  30.             @Override  
  31.             public void windowClosing(WindowEvent e) {  
  32.                 // TODO Auto-generated method stub   
  33.                 System.out.println("窗口将要被关闭!");  
  34.             }  
  35.   
  36.             @Override  
  37.             public void windowClosed(WindowEvent e) {  
  38.                 // TODO Auto-generated method stub   
  39.                 System.out.println("窗口已经被关闭!");  
  40.             }  
  41.   
  42.             @Override  
  43.             public void windowIconified(WindowEvent e) {  
  44.                 // TODO Auto-generated method stub   
  45.                 System.out.println("窗口被图标化!");  
  46.             }  
  47.   
  48.             @Override  
  49.             public void windowDeiconified(WindowEvent e) {  
  50.                 // TODO Auto-generated method stub   
  51.                 System.out.println("窗口被非图标化!");  
  52.             }  
  53.   
  54.             @Override  
  55.             public void windowActivated(WindowEvent e) {  
  56.                 // TODO Auto-generated method stub   
  57.                 System.out.println("窗口被激活!");  
  58.             }  
  59.   
  60.             @Override  
  61.             public void windowDeactivated(WindowEvent e) {  
  62.                 // TODO Auto-generated method stub   
  63.                 System.out.println("窗口不再处于激活状态!");  
  64.             }  
  65.               
  66.         });  
  67.     }  
  68.   
  69.     /** 
  70.      * @param args 
  71.      */  
  72.     public static void main(String[] args) {  
  73.         // TODO Auto-generated method stub   
  74.         WindowEvent_3 frame = new WindowEvent_3();  
  75.         frame.setTitle("捕获其他窗口事件");  
  76.         frame.setVisible(true);  
  77.         frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);  
  78.         frame.setBounds(00300100);  
  79.     }  
  80.   
  81. }  

相关内容