package Demo
;
import javax
.swing
.*
;
import java
.awt
.*
;
import java
.awt
.event
.*
;
import java
.awt
.Window
;
import java
.awt
.event
.*
;
public class Demo extends JFrame{
public void setListener() {
JFrame frame
= new JFrame();
frame
.setSize(300,300);
frame
.setTitle("消音之家");
JButton button
= new JButton("切换按钮");
frame
.add(button
);
frame
.setVisible(true);
frame
.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e
) {
System
.out
.println("程序退出");
System
.exit(0);
}
});
button
.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e
) {
System
.out
.println("程序退出");
System
.exit(0);
}
});
}
public static void main(String
[] args
) {
Demo demo
= new Demo();
demo
.setListener();
}
}
调试 点击切换按钮会关掉这个窗口,实现获取鼠标事件来关掉窗口。
转载请注明原文地址: https://mac.8miu.com/read-510818.html