Java捕獲其他窗口事件 – JAVA編程語言程序開發技術文章


[java]
package com.han; 
 
import java.awt.event.WindowEvent; 
import java.awt.event.WindowListener; 
 
import javax.swing.JFrame; 
 
/**
 * 捕獲其他窗口事件
 * @author HAN
 *
 */ 
public class WindowEvent_3 extends JFrame { 
 
    /**
     * 
     */ 
    private static final long serialVersionUID = 9040264048222645786L; 
 
    public WindowEvent_3() { 
        // TODO Auto-generated constructor stub  
        addWindowListener(new WindowListener() { 
 
            @Override 
            public void windowOpened(WindowEvent e) { 
                // TODO Auto-generated method stub  
                System.out.println("窗口被打開!"); 
            } 
 
            @Override 
            public void windowClosing(WindowEvent e) { 
                // TODO Auto-generated method stub  
                System.out.println("窗口將要被關閉!"); 
            } 
 
            @Override 
            public void windowClosed(WindowEvent e) { 
                // TODO Auto-generated method stub  
                System.out.println("窗口已經被關閉!"); 
            } 
 
            @Override 
            public void windowIconified(WindowEvent e) { 
                // TODO Auto-generated method stub  
                System.out.println("窗口被圖標化!"); 
            } 
 
            @Override 
            public void windowDeiconified(WindowEvent e) { 
                // TODO Auto-generated method stub  
                System.out.println("窗口被非圖標化!"); 
            } 
 
            @Override 
            public void windowActivated(WindowEvent e) { 
                // TODO Auto-generated method stub  
                System.out.println("窗口被激活!"); 
            } 
 
            @Override 
            public void windowDeactivated(WindowEvent e) { 
                // TODO Auto-generated method stub  
                System.out.println("窗口不再處於激活狀態!"); 
            } 
             
        }); 
    } 
 
    /**
     * @param args
     */ 
    public static void main(String[] args) { 
        // TODO Auto-generated method stub  
        WindowEvent_3 frame = new WindowEvent_3(); 
        frame.setTitle("捕獲其他窗口事件"); 
        frame.setVisible(true); 
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
        frame.setBounds(0, 0, 300, 100); 
    } 
 

作者:Gaowen_HAN

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *