Is it possible to dispose a jFrame using a button of another jFrame? If it is possible, how should the codes look like in netbeans?
1 Answers
Is it possible to dispose a jFrame using a button of another jFrame?
Yes.
If it is possible, how should the codes look like in netbeans?
In the JButton's ActionListener:
myOtherFrame.dispose();
Your question in a nutshell is essentially -- how can I call a method on one object from another object, that's it. And the key to doing this is to be sure that you have a decent reference to the object whose behavior you'd like to change (whose method you'd like to call) inside the calling object. So here you'd need a decent reference to the displayed window in order to call a method on it.
Likely my recommendations won't help you all that much since the key to all this is the structure of your program, including the references that you have for the one Jframe in the other class, details that you've not shown or told us.
Also, it is very unlikely that you even want to have more than one JFrame visible at a time as most professional applications have at most one top-level main window (for Swing this is a JFrame) and sometimes have child windows which for Swing would be JDialogs.
Please see: The Use of Multiple JFrames, Good/Bad Practice?.

- 1
- 1

- 283,665
- 25
- 256
- 373