import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Xiti4 {
JFrame f=new JFrame();
public void init()
{
f.addWindowListener(new Guanbi());
f.pack();
f.setVisible(true);
}
public static void main(String[] args)
{
new Xiti4().init();
}
class Guanbi extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
int res=JOptionPane.showConfirmDialog(f,"是否要关闭窗口","窗口",JOptionPane.YES_NO_OPTION);
if(res==JOptionPane.YES_OPTION)
{
System.exit(0);
}
else
return;
}
}
}
为什么我点窗口关闭时候弹出的对话框无论点是或否,都会关闭窗口的?
import java.awt.event.WindowEvent;import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Xiti4 {
JFrame f=new JFrame();
public void init()
{
f.addWindowListener(new Guanbi());
f.pack();
f.setVisible(true);
}
public static void main(String[] args)
{
new Xiti4().init();
}
class Guanbi extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
int res=JOptionPane.showConfirmDialog(f,"是否要关闭窗口","窗口",JOptionPane.YES_NO_OPTION);
if(res==JOptionPane.YES_OPTION)
{
System.exit(0);
}
else
return;
}
}
}
为什么我点窗口关闭时候弹出的对话框无论点是或否,都会关闭窗口的?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货