JFrame确认关闭窗口的问题
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class comFrame extends JFrame implements WindowListener
{
comFrame()
{
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension d=kit.getScreenSize();
this.setSize((int)d.getWidth()/2,(int)d.getHeight()/2);
this.setLocation((int)d.getWidth()/4,(int)d.getHeight()/4);
//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.addWindowListener(this);
this.setVisible(true);
}
public void windowOpened(WindowEvent e) {}
public void windowClosing(WindowEvent e)
{
int option= JOptionPane.showConfirmDialog(
this,"确定退出系统?","提示",JOptionPane.YES_NO_CANCEL_OPTION);
if(option==JOptionPane.YES_OPTION)
if(e.getWindow() == this)
{
System.exit(0);
}
else
{
return;
}
}
public void windowClosed(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public static void main(String[] args)
{
comFrame aFrame=new comFrame();
}
}
在按下frame(只有一个frame)的关闭键后我想弹出一个确认用的JOptionPane如果选择否,则不退出应该怎么做(不关闭该frame)。但以上代码在SDK1.5中测试,收到cancle和no的消息后,frame仍旧关闭,但是系统中仍存在一个多出来的javaw.exe进程。不知哪里有错。请教