📄 eventsample2.java
字号:
// 例6.2.2 EventSample2.java
import java.awt.event.*;
import javax.swing.*;
public class EventSample2
{
JFrame frame;
class MyWindowListener implements WindowListener //内部类
{
public void windowClosing(WindowEvent e)
{
frame.setVisible(false);
frame.dispose();
System.exit(0);
}
public void windowActivated(WindowEvent e){ }
public void windowClosed(WindowEvent e){ }
public void windowDeactivated(WindowEvent e){ }
public void windowDeiconified(WindowEvent e){ }
public void windowIconified(WindowEvent e){ }
public void windowOpened(WindowEvent e){ }
}
public EventSample2() // 构造函数
{
frame=new JFrame(); // 创建一个窗体框架
frame.setTitle("事件演示程序");
frame.setSize(300,200);
frame.setVisible(true);
frame.addWindowListener(new MyWindowListener());
}
public static void main(String[] args)
{
new EventSample2();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -