How to close a frame on action event of a button from a different class ?
I have a designed a control-frame on 1 class which has jbutton components, I have coded like on action event of these components diff-diff frame get initialized. For each frame there is a class. now I want to close the frame (which was opened when I had press first jbutton from control-frame) when I press second jbutton from control-frame.
hi friend,
I think you want to do different operations on different frames inside the main frame. You can create internal frames inside the main frames and you may do your operations there.
To create internal frames you may use JInternalFrame class.
For reading more in detail you may go through the following link, may this will be helpful for you.
http://roseindia.net/java/example/java/swing/how-to-create-internal-frame.shtml
Thanks.
hi friend,
you can use the dispose() method of java.awt.Window class to close the frame on button click event.
For detail tutorial you can go through the following link, may this will be helpful for you
http://roseindia.net/java/example/java/swing/frame-close-on-button-click.shtml
Thanks.
Thanks for your answer. Thats true that we can get close frame by dispose method if it is in same class (or you can say from same frame, you can close itself by dispose()). I am creating 1 application which has 1 frame which I want to keep open till application running. In this frame there are several buttons and on their action event other frames will open relevant to that button, now if after pressing button 1 if I press button 2 then first button frame will be there and 2nd button's frame will be also there. So to avoid this I have to send close signal to the first frame when second button pressed but while I press any button on main Frame focus or control is on this main frame so it will not identified the another frame even if I use objFrame2.dispose();
Ads