当前位置:编程学习 > 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
补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,