📄 10.32windoweventsample.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class WindowEventSample extends JFrame implements WindowListener {
public WindowEventSample(){
super("Window Eyent Sample"); //显示调用父类方法
Container container = getContentPane();
container.setLayout(new FlowLayout()); //设置容器为流布局
JLabel label1 = new JLabel("This is a Window event test!");
label1.setFont(new Font("Serif",Font.BOLD,20)); //设置标签字体
label1.setForeground(Color.red); //设置标签字体颜色
container.add(label1);
addWindowListener(this); //设置事件监听
setSize(300,200);
setVisible(true);
}
public void windowClosing (WindowEvent e) { //窗口关闭事件处理函数
System.exit (0) ; //关闭窗口时退出
}
public void windowClosed(WindowEvent e) {} //各种窗口事件处理函数
public void windowOpened(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public static void main(String []args) {
JFrame sample = new WindowEventSample();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -