/Users/lyon/j4p/src/gui/ExitFrame.java

1    package gui; 
2     
3    import javax.swing.*; 
4    import java.awt.*; 
5    import java.awt.event.WindowAdapter; 
6    import java.awt.event.WindowEvent; 
7     
8    /** 
9     * The <code>ExitFrame</code> 
10    * will terminate the JVM upon 
11    * closing. This is suggested 
12    * for JAWS, so that resources 
13    * can be released. 
14    */ 
15   public class ExitFrame extends JFrame { 
16       public ExitFrame() { 
17           this(""); 
18       } 
19    
20       public ExitFrame(String title) { 
21           super(title); 
22           setBackground(Color.white); 
23           addWindowListener( 
24                   new ClosingWindowAdapter()); 
25       } 
26    
27       public void addMouseController(gui.mouse.MouseController mc) { 
28           addMouseMotionListener(mc); 
29           addMouseListener(mc); 
30       } 
31    
32       public static void main(String args[]) { 
33           ExitFrame cf = new ExitFrame("ClosableJFrame"); 
34           cf.setSize(200, 200); 
35           cf.setVisible(true); 
36    
37       } 
38    
39       private class ClosingWindowAdapter 
40               extends WindowAdapter { 
41           public void windowClosing(WindowEvent e) { 
42               setVisible(false); 
43               dispose(); 
44               System.exit(0); 
45           } 
46       } 
47   }