.
*
* Copyright (C) 1996 Massachusetts Institute of Technology.
* Please do not redistribute without obtaining permission.
*/
package cs101.awt;
import java.awt.*;
import java.awt.event.*;
/**
* Simple top level that deals with one component and sizing.
*
* Copyright (c) 1996, 1998, 1999 Massachusetts Institute of Technology
*
* @author Paul K. Njoroge, pnjoroge@mit.edu
* @author Todd C. Parnell, tparnell@ai.mit.edu
* @author
* @author Lynn Andrea Stein, las@ai.mit.edu
* @version $Id: DefaultFrame.java,v 1.2 2002/11/25 15:20:08 gus Exp $
*/
public class DefaultFrame extends Frame {
/** The Component to display. */
protected Component c;
/** Default Frame dimensions. Initialized in constructor **/
private Dimension defaultDimension;
/**
* Creates a new frame surrounding the supplied component.
* Does not show the frame. To show the frame, use init().
*
* In the absence of a user-specified dimension, this is where
* defaultDimension gets its value.
*
* @see #DefaultFrame( Component, Dimension )
* @see #init
*
* @param c Component to display.
*/
public DefaultFrame(Component c)
{
this(c, (new Dimension(400,300)));
}
/**
* Creates a new frame of the specified size surrounding the
* supplied component. Does not show the frame. To show the frame,
* use init().
*
* @see #DefaultFrame( Component, Dimension )
* @see #init
*
* @param c Component to display.
* @param x preferred horizontal dimension of the Frame (in pixels)
* @param y preferred vertical dimension of the Frame (in pixels)
*/
public DefaultFrame(Component c, int x , int y)
{
this(c,(new Dimension(x,y)));
}
/**
* Creates a new frame of the specified Dimension surrounding the
* supplied component. Does not show the frame. To show the frame,
* use init().
*
* This frame supplies a quit button (which kills off the entire
* application) and the title "Default". Use setTitle to change the
* title.
*
* @see #DefaultFrame( Component, Dimension )
* @see #init
*
* @param c Component to display.
* @param d preferred Dimension of the Frame (in pixels)
*/
public DefaultFrame(Component c, Dimension d)
{
super("Default");
this.c=c;
this.defaultDimension=d;
this.pack();
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
DefaultFrame.this.dispose();
System.exit(0);
}
});
setLayout(new FlowLayout());
Button QuitButton = new Button("Quit");
this.add(QuitButton);
QuitButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
DefaultFrame.this.dispose();
System.exit(0);
}
});
}
/**
* This method overrides Frame's default getPreferredSize() in case
* component doesn't specify its own preferences. Without this
* method, the DefaultFrame has a disconcerting tendency to paint
* itself into a tiny little corner....
*
* @see java.awt.Frame#getPreferredSize()
*
* @return the default dimension supplied to (or by) the constructor
*/
public Dimension getPreferredSize(){
return this.defaultDimension;
}
/**
* Make the frame appear
*/
public void init() {
this.add("Center",c);
this.show();
}
}
/*
* $Log: DefaultFrame.java,v $
* Revision 1.2 2002/11/25 15:20:08 gus
* fix javadoc error.
*
* Revision 1.1.1.1 2002/06/05 21:56:32 root
* CS101 comes to Olin finally.
*
* Revision 1.10 1999/11/01 01:52:15 mharder
* Fixed NullPointerException in constructor
*
* Revision 1.9 1999/08/16 16:56:47 jsmthng
* Updated to make JavaDoc happy.
*
* Revision 1.8 1999/07/27 18:55:50 las
* Patched up DefaultFrame (mostly docs) and DefaultGameFrame (aesthetics
* and docs).
*
* Capitalized the name of the GameControllable interface.
*
* Moved the other four interfaces (Pausable, Resetable, Startable,
* Stoppable) to cs101.util as they really have nothing to do w/awt or
* windowing in particular.
*
* Also, added unpause() to Pausable as it doesn't make much sense to be
* able to pause but not unpause something.
*
* Revision 1.7 1999/07/13 20:42:47 pnjoroge
* This is a new implementation of DefaultGameFrame. The frame has
* four functionalities that have to be implemented by the user . This
* include start, stop, resetand pause.
*
* Revision 1.6 1998/07/24 17:06:27 tparnell
* Placate new javadoc behavior
*
* Revision 1.5 1998/07/22 18:18:35 tparnell
* migration from cs101.util to cs101.*
*
* Revision 1.4 1998/07/21 19:26:55 tparnell
* added javadoc
*
* Revision 1.3 1998/06/03 19:05:01 tparnell
* added log to bottom of file
*
*/