java窗口询问关闭
答案:1 悬赏:40 手机版
解决时间 2021-02-04 04:39
- 提问者网友:黑米和小志
- 2021-02-03 15:41
f.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { cls(); System.exit(0); } }); 关闭窗口 怎么里面的方法没有作用啊,没有弹出询问窗口,而令建个按钮这方法确正常能用
最佳答案
- 五星知识达人网友:逐風
- 2021-02-03 17:00
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class TestCloseFrame extends JFrame {
TestCloseFrame() {
this.setTitle("测试窗体");
this.setBounds(30, 30, 300, 200);
this.setVisible(true);
}
public static void main(String a[]) {
new TestCloseFrame();
}
protected void processWindowEvent(WindowEvent e) {
//super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
int index = JOptionPane.showConfirmDialog(this, "您好,您确定要关闭窗体吗?",
"确认对话框", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (index == 0) {//如果点击的是确认
System.exit(0);
} else { //否则什么也不做
}
}
}
}
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class TestCloseFrame extends JFrame {
TestCloseFrame() {
this.setTitle("测试窗体");
this.setBounds(30, 30, 300, 200);
this.setVisible(true);
}
public static void main(String a[]) {
new TestCloseFrame();
}
protected void processWindowEvent(WindowEvent e) {
//super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
int index = JOptionPane.showConfirmDialog(this, "您好,您确定要关闭窗体吗?",
"确认对话框", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (index == 0) {//如果点击的是确认
System.exit(0);
} else { //否则什么也不做
}
}
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯