package com.han;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import javax.swing.JFrame;
/**
* 捕获窗口焦点事件
* @author HAN
*
*/
public class WindowEvent_1 extends JFrame {
/**
*
*/
private static final long serialVersionUID = 6385933774053272194L;
public WindowEvent_1() {
// TODO Auto-generated constructor stub
addWindowFocusListener(new WindowFocusListener() {
@Override
public void windowGainedFocus(WindowEvent e) {
// TODO Auto-generated method stub
System.out.println("窗口获得了焦点!");
}
@Override
public void windowLostFocus(WindowEvent e) {
// TODO Auto-generated method stub
System.out.println("窗口失去了焦点!");
}
});
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
WindowEvent_1 frame = new WindowEvent_1();
frame.setTitle("捕获窗口焦点事件");
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(0, 0, 300, 100);
}
}
Java捕获窗口焦点事件
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
JS比较常用的隔行换色和获取焦点以及失去焦点效果
JS比较常用的隔行换色和获取焦点以及失去焦点效果
获取焦点 失去焦点 背景色