-1

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.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) 2) Please add an upper case letter at the start of sentences. Also use a capital for the word I & proper names like Java, and abbreviations and acronyms like JEE or WAR. This makes it easier for people to understand and help. – Andrew Thompson May 14 '13 at 09:22

1 Answers1

2

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);
Alexis C.
  • 91,686
  • 21
  • 171
  • 177