本文概述
- WindowListener接口的方法
- Java WindowListener示例
WindowListener接口的方法 在WindowListener界面中找到的7种方法的签名如下:
public abstract void windowActivated(WindowEvent e);
public abstract void windowClosed(WindowEvent e);
public abstract void windowClosing(WindowEvent e);
public abstract void windowDeactivated(WindowEvent e);
public abstract void windowDeiconified(WindowEvent e);
public abstract void windowIconified(WindowEvent e);
public abstract void windowOpened(WindowEvent e);
Java WindowListener示例
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class WindowExample extends Frame implements WindowListener{
WindowExample(){
addWindowListener(this);
setSize(400, 400);
setLayout(null);
setVisible(true);
}
public static void main(String[] args) {
new WindowExample();
}
public void windowActivated(WindowEvent arg0) {
System.out.println("activated");
}
public void windowClosed(WindowEvent arg0) {
System.out.println("closed");
}
public void windowClosing(WindowEvent arg0) {
System.out.println("closing");
dispose();
}
public void windowDeactivated(WindowEvent arg0) {
System.out.println("deactivated");
}
public void windowDeiconified(WindowEvent arg0) {
System.out.println("deiconified");
}
public void windowIconified(WindowEvent arg0) {
System.out.println("iconified");
}
public void windowOpened(WindowEvent arg0) {
System.out.println("opened");
}
}
【Java WindowListener接口】输出:
文章图片
文章图片
推荐阅读
- Java中的集合
- Java MouseMotionListener接口
- Java MouseListener接口
- 39个无需注册的最佳免费电子书下载网站推荐合集
- 路由器上的WPS按钮是什么(它是如何工作的?)
- 如何在Mac上截屏(Mac截屏的7种最佳方法)
- Windows 10中启动时的Adob??e GC Invoker Utility是什么(提示和指南)
- 推广定制T恤的8个最有效的想法(提示和技巧)
- win10能用office2003吗?