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);
}
}
Java捕获其他窗口事件
最新推荐文章于 2021-02-26 05:48:00 发布