|
How to hide a Frame when its close button has been clicked |
|
|
This Java tip illustrates a method of hiding an application frame when its frame is closed. In Java, when the closed button is clicked there is no action defined by default. Generally developer
would like to end the application when the frame is closed but if there is a need to reuse the frame
for later use the frame can be hidden rather than disposing it.
// Application frame
Frame applicationframe = new Frame();
// Add a listener for the close event
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
Frame applicationframe = (Frame)evt.getSource();
// Hide the frame by setting its visibility as false
frame.setVisible(false);
// Further If the frame is no longer needed, call dispose
frame.dispose();
}
});
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.