Java Reference
In-Depth Information
File: its/CleanUpFrame/CleanUpFrame.java
package its.CleanUpFrame;
1.
2.
3.
import javax.swing.JFrame;
4.
import java.awt.event.WindowAdapter;
5.
import java.awt.event.WindowEvent;
6.
7.
public class CleanUpFrame extends JFrame
8.
{
9.
public CleanUpFrame()
10.
{
11.
this .setSize(200,200);
12.
this .setLocation(200,200);
13.
this .setTitle("CleanUpFrame");
14.
CleanUpAdapter cleaner = new CleanUpAdapter();
15.
this .addWindowListener(cleaner);
16.
}
17.
18.
public void showIt(){
this .setVisible( true );
19.
}
20.
21.
22.
public void hideIt(){
this .setVisible( false );
23.
}
24.
25.
26.
// Performs the clean up work before terminating the application.
27.
private static void cleanUp(){
28.
// Real code for the clean up goes here.
29.
System.out.println("Cleaning up and then terminating the program.");
30.
System.exit(0);
31.
}
32.
// Internal class
33.
private class CleanUpAdapter extends WindowAdapter{
34.
35.
public void windowClosing(WindowEvent we)
36.
{
37.
// Call the cleanUp method of the frame.
38.
cleanUp();
39.
}
40.
}// internal class
}
41.
Search WWH ::




Custom Search