Share on Google+Share on Google+

Nishant Patel
How to close a frame on action event of a button from a different class ?
3 Answer(s)      4 years and a month 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.

Ads

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:
Tutorials   
Java Spring Hibernate Struts Training Change JPanel background color from mouse entered/exit event JTable Pagination Jcombobox JAVA SWING how can i display a pdf file in a jtextarea Crop Image Code in Applet Crop Image Code in Applet Image Manipulation in Swing AWT Applet Ho to get virtual key code. how to show set of images continously using JScrollpane in java how to show set of images continously using JScrollpane in java How to connect on screen keyboard to system. How to connect on screen keyboard to system. query java client server program for playing video file(stored in folder in the same workspace) using swings java client server program for playing video file(stored in folder in the same workspace) using swings java client server program for playing video file(stored in folder in the same workspace) using swings java client server program for playing video file(stored in folder in the same workspace) using swings Download. how to open one Jframe from main method call Urgent requirement display shapes i am getting an error in adding a menu item to a menu. I am trying to develop a Image Sliding application but unfortunately its not working... Can any one help me in this Sliding window protocol how to update the value of jslider how to update the value of jslider how to update the value of jslider how to update the value of jslider how to update the value of jslider Jbutton in JTable cells program code java textfield problem swing retrieve data from database in java swing form using prev n next buttons retrieve data from database in java swing form using prev n next buttons How to close a frame on action event of a button from a different class ? searching the data swings for webnms Jpanel allignment pass data from java frame to file code for traffic control system simulation Bank Management System how to maKE Jcombox editable after saveing value init. i havei) aJTextField and one button. when place the cursor or enter anything in the test field then only button should be enabled.by default the button should be disabled. i havei) a jtable with few cloumns and few rows andii) one button. when place the cursor in any of the table's column cell. i need to enable the button.by default the button should be disabled. PDF Comparator i have JTextfield and JComboBox. there are several values in combobox.when i select a value from combobox how to make textfiled as a combobox. issue on jcombobox

Ads

 
Advertisement null

Ads