-1

我有2个jframe(假设A和B),当我关闭一个jframe(A)时,我需要显示其他jframe(B)我有一个线索,我需要覆盖defaultClosingOperation,但我不知道该怎么做。任何帮助将不胜感激..谢谢大家。

4

1 回答 1

2

您可以将Windows 侦听器添加到您的框架。

WindowListener myExitListener = new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                int confirmation = JOptionPane.showOptionDialog(jframe1, "Open frame2", "Open frame2", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
                if (confirmation == 0) {
                  //open jframe2 here
                }
            }
        };


jframe1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
jframe1.addWindowListener(myExitListener);
于 2013-05-14T09:23:35.343 回答