class ExitWindow extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
int response;
response=JOptionPane.showConfirmDialog(null,"真的要退出吗?");
if(response==JOptionPane.YES_OPTION)
{
System.exit(0);
}
}
}
public class Test2
{
public static void main(String[] args)
{
Test test=new Test();
ExitWindow exit=new ExitWindow();
test.addWindowListener(exit);
}
}