processWindowEvent已经提供了退出机制,那么setDefaultCloseOperation(EXIT_ON_CLOSE);这句就可以不用写啦……
非常感谢2位版主的帮忙~
非常感谢2位版主的帮忙~
向着软件工程师的目标前进!
老kai真是会算计我啊,嘿嘿,连反例都给准备好了,哈哈。让事实说话吧。 import java.awt.event.*; import javax.swing.*;
public class FrameExit extends WindowAdapter { public static void main(String args[]) { JFrame jf = new JFrame("AskExit"); jf.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); jf.addWindowListener(new FrameExit()); jf.setSize(200,200); jf.setVisible(true); } public void windowClosing(WindowEvent e) { int choice = JOptionPane.showConfirmDialog(null,"relly want to exit?","fuck kai:)",JOptionPane.YES_NO_OPTION); if(choice == JOptionPane.YES_OPTION) { System.exit(0); } } }