我正在做一些基本的Java Swing application
(初學者級別)。 什麼,我要做的就是當我按下close button on JFrame
到colse的窗口,我想一個JOptionPane Confirm Dialog
,而不是直接的密切JFrame的彈出式關閉按鈕
這裏是代碼的JFrame
JFrame frame= new JFrame("frame");
frame.setSize(300,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.pack();
和JOptionPane的代碼是這樣
final JOptionPane optionPane = new JOptionPane("Are You sure?",JOptionPane.QUESTION_MESSAGE,
JOptionPane.YES_NO_OPTION);
所以當關閉按鈕上JFrame按下這個彈出應該出來而不是直接關閉
請指導我如何做到這一點..謝謝提前
看看[這裏](http://stackoverflow.com/questions/3777146/how-can-a-swing- windowlistener-veto-jframe-closing) – MadProgrammer 2013-03-04 09:47:31