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);
	}

}


posted on   java课程设计例子  阅读(238)  评论(0编辑  收藏  举报

< 2012年7月 >
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 1 2 3 4
5 6 7 8 9 10 11

统计

点击右上角即可分享
微信分享提示