001    /*
002     * cs101 DefaultFrame
003     * $Id: DefaultFrame.java,v 1.2 2002/11/25 15:20:08 gus Exp $
004     *
005     * Developed for "Rethinking CS101", a project of Lynn Andrea Stein's AP Group.
006     * For more information, see <a href="http://www.ai.mit.edu/projects/cs101/">the
007     * CS101 homepage</a> or email <las@ai.mit.edu>.
008     *
009     * Copyright (C) 1996 Massachusetts Institute of Technology.
010     * Please do not redistribute without obtaining permission.
011     */
012    
013    package cs101.awt;
014    
015    import java.awt.*;
016    import java.awt.event.*;
017    
018    
019    
020    /** 
021     * Simple top level that deals with one component and sizing.
022     *
023     * <P>Copyright (c) 1996, 1998, 1999 Massachusetts Institute of Technology
024     *
025     * @author Paul K. Njoroge, pnjoroge@mit.edu
026     * @author Todd C. Parnell, tparnell@ai.mit.edu
027     * @author <nathanw@mit.edu>
028     * @author Lynn Andrea Stein, las@ai.mit.edu
029     * @version $Id: DefaultFrame.java,v 1.2 2002/11/25 15:20:08 gus Exp $
030     */
031    public class DefaultFrame extends Frame {
032      /** The Component to display. */
033      protected Component c;
034    
035      /** Default Frame dimensions.  Initialized in constructor **/
036      private Dimension defaultDimension;
037    
038      /** 
039       * Creates a new frame surrounding the supplied component.  
040       * Does not show the frame.  To show the frame, use init().
041       *
042       * In the absence of a user-specified dimension, this is where
043       * defaultDimension gets its value.
044       *
045       * @see #DefaultFrame( Component, Dimension )
046       * @see #init
047       *
048       * @param c Component to display.  
049       */
050      public DefaultFrame(Component c)
051      {
052        this(c, (new Dimension(400,300)));
053      }
054    
055      /** 
056       * Creates a new frame of the specified size surrounding the
057       * supplied component.  Does not show the frame.  To show the frame,
058       * use init().
059       *
060       * @see #DefaultFrame( Component, Dimension )
061       * @see #init
062       *
063       * @param c Component to display.  
064       * @param x preferred horizontal dimension of the Frame (in pixels) 
065       * @param y preferred vertical dimension of the Frame (in pixels) 
066       */
067      public DefaultFrame(Component c, int x , int y)
068      {
069        this(c,(new Dimension(x,y)));
070      }
071      
072      /** 
073       * Creates a new frame of the specified Dimension surrounding the
074       * supplied component.  Does not show the frame.  To show the frame,
075       * use init().
076       *
077       * This frame supplies a quit button (which kills off the entire 
078       * application) and the title "Default".  Use setTitle to change the 
079       * title.
080       *
081       * @see #DefaultFrame( Component, Dimension )
082       * @see #init
083       *
084       * @param c Component to display.  
085       * @param d preferred Dimension of the Frame (in pixels) 
086       */
087      public DefaultFrame(Component c, Dimension d) 
088      {
089        super("Default");
090        this.c=c;
091        this.defaultDimension=d;
092        this.pack();
093        
094        this.addWindowListener(new WindowAdapter() 
095                               {
096                                 public void windowClosing(WindowEvent e) 
097                                   {
098                                     DefaultFrame.this.dispose();
099                                     System.exit(0);
100                                   }
101                               });
102        
103        setLayout(new FlowLayout());
104        Button QuitButton = new Button("Quit");
105        
106        this.add(QuitButton);
107        
108        QuitButton.addActionListener(new ActionListener()
109                                     {
110                                       public void actionPerformed(ActionEvent evt)
111                                         
112                                         {
113                                           DefaultFrame.this.dispose();
114                                           System.exit(0);
115                                         }
116                                     });
117      }
118      
119      /** 
120       * This method overrides Frame's default getPreferredSize() in case
121       * component doesn't specify its own preferences.  Without this
122       * method, the DefaultFrame has a disconcerting tendency to paint
123       * itself into a tiny little corner....
124       *
125       * @see java.awt.Frame#getPreferredSize()
126       *
127       * @return the default dimension supplied to (or by) the constructor 
128       */
129      public Dimension getPreferredSize(){
130        return this.defaultDimension;
131      }
132      
133      /**
134       * Make the frame appear 
135       */
136      public void init() {
137        this.add("Center",c);
138        this.show();
139      }
140      
141    }
142    
143    /*
144     * $Log: DefaultFrame.java,v $
145     * Revision 1.2  2002/11/25 15:20:08  gus
146     * fix javadoc error.
147     *
148     * Revision 1.1.1.1  2002/06/05 21:56:32  root
149     * CS101 comes to Olin finally.
150     *
151     * Revision 1.10  1999/11/01 01:52:15  mharder
152     * Fixed NullPointerException in constructor
153     *
154     * Revision 1.9  1999/08/16 16:56:47  jsmthng
155     * Updated to make JavaDoc happy.
156     *
157     * Revision 1.8  1999/07/27 18:55:50  las
158     * Patched up DefaultFrame (mostly docs) and DefaultGameFrame (aesthetics
159     * and docs).
160     *
161     * Capitalized the name of the GameControllable interface.
162     *
163     * Moved the other four interfaces (Pausable, Resetable, Startable,
164     * Stoppable) to cs101.util as they really have nothing to do w/awt or
165     * windowing in particular.
166     *
167     * Also, added unpause() to Pausable as it doesn't make much sense to be
168     * able to pause but not unpause something.
169     *
170     * Revision 1.7  1999/07/13 20:42:47  pnjoroge
171     * This is a new implementation of DefaultGameFrame. The frame has
172     * four functionalities that have to be implemented by the user . This
173     * include start, stop, resetand pause. 
174     *
175     * Revision 1.6  1998/07/24 17:06:27  tparnell
176     * Placate new javadoc behavior
177     *
178     * Revision 1.5  1998/07/22 18:18:35  tparnell
179     * migration from cs101.util to cs101.*
180     *
181     * Revision 1.4  1998/07/21 19:26:55  tparnell
182     * added javadoc
183     *
184     * Revision 1.3  1998/06/03 19:05:01  tparnell
185     * added log to bottom of file
186     *
187     */      
188    
189        
190        
191