I am currently writing a little program in Swing.
I have something I do not know how to do.
At some point in the program I have a window, let's call it window A. I want, if the user closes the window A by clicking on the closing cross, to close window A and to show the main menu window. This I can do.
To do that, I used a class that implements WindowListener. In that class, I defined the windowClosed method, in which I show the main menu window.
In my window A I set the listener and the default close operation.
The problem is, at some point in my code, I want to close window A and go to another window B, without showing the main menu window. And I have no clue how to do that.
So currently, if the user closes window A, it disposes the window A and shows the main menu window. I want that.
But if I use the dispose() method on window A, it also shows the main menu window. I don't want that.
Thanks in advance for your help. I hope I was clear.
Are you using the class called Window (or JWindow)? Don't. Use JFrame or, better still, a dialogue. You will have to return something from the dialogue to tell its parent frame whether you want the menu visible or not.
Why do you want menus appearing and disappearing? That will give your display a very peculiar appearance.
Are you extending display classes? That is usually a bad idea; your program IS NOT A JFrame, but is HAS A JFrame. You should usually only use one frame per program; everything else is better as a dialogue.