Prof.Merlin
Expert Member
- Joined
- Aug 2, 2006
- Messages
- 1,682
Hi
Let me start with the basics. I have used netbeans's JFrame creator for this project(even though that should not make a difference). I have several classes, each class with its own JFrame.
The mainFrame has a menu with many menu items in it. Each time a menu item is selected, it opens the new JFrame in new class and hides the mainFrame(or setvisible(false)).
EG: I have a menuItem called 'about'. I select it, the about window appears. The mainFrame then disappears.
When the user selects the 'OK' button, the about window closes and the mainFrame then reappears again.
The current way I am doing it is in the about class, in the actionperformed method for the 'ok button' I have the following code:
I know this is incorrect as it creates a new instance of the mainFrame each time. And with lots of menu Items being selected, it will just cause problems.
I have read up on using a window Listener, but not entirely sure how to use it as i need to use different classes in the window listener.
Do any of you maybe know a solution to my problem?
Thanks
Let me start with the basics. I have used netbeans's JFrame creator for this project(even though that should not make a difference). I have several classes, each class with its own JFrame.
The mainFrame has a menu with many menu items in it. Each time a menu item is selected, it opens the new JFrame in new class and hides the mainFrame(or setvisible(false)).
EG: I have a menuItem called 'about'. I select it, the about window appears. The mainFrame then disappears.
When the user selects the 'OK' button, the about window closes and the mainFrame then reappears again.
The current way I am doing it is in the about class, in the actionperformed method for the 'ok button' I have the following code:
Code:
dispose();
MainFrame frame = new MainFrame();
frame.setVisible(true);
I know this is incorrect as it creates a new instance of the mainFrame each time. And with lots of menu Items being selected, it will just cause problems.
I have read up on using a window Listener, but not entirely sure how to use it as i need to use different classes in the window listener.
Do any of you maybe know a solution to my problem?
Thanks