문제

I have 2 jframes(assume A and B) and when I close a one jframe(A) I need to show other jframe(B) I have a clue that I need to override defaultClosingOperation but I have no idea how to do that.any help would be appreciated .. thank you all.

도움이 되었습니까?

해결책

You can add a Windows Listener to your frame.

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top