Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Swing-AWT How to close a frame on action event of a button from a different class ?

Have Programming Question? Ask it here!
 
 
 


Nishant Patel
How to close a frame on action event of a button from a different class ?
3 Answer(s)      a year and 4 months ago
Posted in : Swing AWT


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.


Advertisement
View Answers

May 29, 2013 at 5:15 PM


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.



March 5, 2013 at 6:53 PM


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.



March 14, 2013 at 8:31 PM


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();



Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com