Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to close one Frame?

Status
Not open for further replies.

snowhot

Programmer
Jul 18, 2001
3
US
In frame A, after click one button, frame B will be envoked. In frame B , after click button "close" , I want to close frame B, so I use: System.exit(0). , but all frames will be closed.

Can you tell me how to close just frame B ? thanks very much.
 
system.exit terminates the process so you can not use that command.

exactly what type of frame are you using??
 
To close a frame, call the
Code:
dispose
method on a reference to that frame. This will both hide the window and reclaim all resources - the frame can be shown again with a call to
Code:
setVisible
or similar, which will recreate the frame and its components.

Alternatively (Not recommended unless hyper-optimising for speed), you could just hide the window (
Code:
setVisible(false)
) and let the resources be reclaimed when the entire application exits. Note that threads owned by this frame will not be reclaimed in this way, so the application should (must) be stopped with
Code:
System.exit
, or it will run indefinitely.

For more information, the
Code:
dispose
method is defined in
Code:
java.awt.Window
.

Regards,

--
Troy Laurin
<troy@firestarter.com.au>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top