/**
* 初始化窗休面板
* @return void
*/
private void initialize() {
this.setSize(600, 400);
this.setContentPane(getJContentPane());
this.setTitle(XmlConfig.getValue("title"));
this.setLocation();
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent arg0) {
super.windowClosing(arg0);
JOptionPane op=new JOptionPane();
int ret=op.showConfirmDialog(null,"确定要关闭应用程序吗?","关闭提示",JOptionPane.OK_CANCEL_OPTION);
if(JOptionPane.OK_OPTION==ret){
ScanThread.flag = true; // 设置线程类,状态
System.exit(0);
}else{
op.showMessageDialog(null, "当前已经在windowclosing中,要退出去,似乎不行了,寻高手解决它。");
}
}
});
this.setVisible(true);
}以上方法完成初始化一个Frame窗体.我现在想要实现点关闭的X时,提示一下,如果用户取消关闭.我就不想关窗体了.请问高手怎么解决它?
解决方案 »
- 异常处理中的system.exit(-1);
- 怎么去取一段文字中的邮件地址
- 一个java的低级问题
- 数组的length属性:byte[][] a; int i=a.length这里的i值应是多少?
- java中cookies怎么复设置值,怎么取值
- SqlServer1433端口不开
- 看到一个.bat 文件,里面有这么一句,看不懂
- 绘图闪烁的问题,捆饶多时了。
- 寻树型java代码,实现从数据库取出数据,能够直接在树上添加/删除节点,并自动更新!
- 如何在DIALOG上画出一个有一定宽度的绿色的向下的箭头呢?
- 我写了个swt窗口,然后想在桌面上显示,不想在任务栏中显示,请大侠帮解决一下,没看懂的请看下面的图。
- 帮忙解释输出结果
frame.addWindowListener(new WindowAdapter() {})import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;import javax.swing.JFrame;
import javax.swing.JOptionPane;public class FrameTest { public static void main(String[] args) {
JFrame frame = new JFrame("test");
frame.setSize(500, 400);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent arg0) {
int k = JOptionPane.showConfirmDialog((JFrame) arg0.getSource(), "你确定退出程序嘛?",
"Exit Confirm", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (k == 0) {
System.out.println("exit program");
System.exit(0);
}else {
return ;
}
}
});
}
}
* 重载该方法,以便在窗口关闭时,能退出
* @param e WindowEvent windows事件
*/
protected void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
JOptionPane op = new JOptionPane();
int ret = op.showConfirmDialog(null, "确定要关闭应用程序吗?", "关闭提示",JOptionPane.OK_CANCEL_OPTION);
if (JOptionPane.OK_OPTION == ret) {
System.exit(0);
} else {
op.showMessageDialog(null,"当前已经在windowclosing中,要退出去,似乎不行了,寻高手解决它。");
return;
}
}
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
Runtime.getRuntime().halt(0);
}
}