Java Swing为EXIT_ON_CLOSE添加Action Listener
- 论坛
- Java Swing为EXIT_ON_CLOSE添加Action Listener
11 浏览
Java Swing为EXIT_ON_CLOSE添加Action Listener
我有一个简单的GUI:
public class MyGUI extends JFrame{ public MyGUI(){ run(); } void run(){ setSize(100, 100); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 可能在这里添加一个动作监听器 } }
我想在GUI关闭时(当按下X按钮时)打印出这条消息:
System.out.println("Closed");
我该如何做到这一点?