acm.graphics
Class GFrame

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Frame
                          |
                          +--javax.swing.JFrame
                                |
                                +--acm.graphics.GFrame

public class GFrame extends JFrame

The GFrame class is a top-level Swing window that contains a GCanvas that fills the area of the frame.


Field Summary
static int BACK_TO_FRONT
Specifies that iterators should run from back to front
static int FRONT_TO_BACK
Specifies that iterators should run from front to back
 
Constructor Summary
GFrame()
Creates a new untitled GFrame containing a single GCanvas.
GFrame(String title)
Creates a new GFrame containing a single GCanvas.
 
Method Summary
void add(GObject gobj)
Adds a new graphical object to this container.
void add(GObject gobj, double x, double y)
Adds the graphical object to this canvas and sets its location to the point (xy).
void add(GObject gobj, java.awt.Point pt)
Adds the graphical object to this canvas and sets its location to the specified point.
GCanvas createGCanvas()
Creates the GCanvas used by the GFrame.
MenuBar createMenuBar()
Creates the menu bar used by this GFrame.
GObject getElement(int index)
Returns the graphical object at the specified index, numbering from back to front in the stacking order.
GObject getElementAt(double x, double y)
Returns the topmost graphical object that contains the point (x, y), or null if no such object exists.
int getElementCount()
Returns the number of graphical objects stored in this GCanvas.
GCanvas getGCanvas()
Returns the GCanvas object used by this frame.
boolean isAutoRepaintEnabled()
Returns the current setting of the auto-repaint flag as described in setAutoRepaintEnabled.
Iterator iterator()
Returns an Iterator that cycles through the elements within this container in the default direction, which is from back to front.
Iterator iterator(int direction)
Returns an Iterator that cycles through the elements within this container in the specified direction, which must be one of the constants FRONT_TO_BACK or BACK_TO_FRONT.
void onMouseClicked(double x, double y)
This method is invoked automatically whenever a mouse click occurs in the canvas.
void onMouseDragged(double x, double y)
This method is invoked automatically whenever a mouse click occurs in the canvas.
void onMouseMoved(double x, double y)
This method is invoked automatically whenever a mouse click occurs in the canvas.
void onMousePressed(double x, double y)
This method is invoked automatically whenever a mouse click occurs in the canvas.
void onMouseReleased(double x, double y)
This method is invoked automatically whenever a mouse click occurs in the canvas.
void remove(GObject gobj)
Removes a graphical object from this container.
void removeAll()
Removes all graphical objects from this container.
void removeAllComponents()
Removes all components from this container.
void setAutoRepaintEnabled(boolean state)
Changes the setting of the auto-repaint flag.
 

Field Detail

public static final int BACK_TO_FRONT

Specifies that iterators should run from back to front

public static final int FRONT_TO_BACK

Specifies that iterators should run from front to back
Constructor Detail

public GFrame()

Creates a new untitled GFrame containing a single GCanvas.
 
Usage: GFrame frame = new GFrame();
 

public GFrame(String title)

Creates a new GFrame containing a single GCanvas. The title parameter is used to set the title of the frame.
 
Usage: GFrame frame = new GFrame(title);
 
Method Detail

public void add(GObject gobj)

Adds a new graphical object to this container.
 
Usage: frame.add(gobj);
Parameter: 
gobj  The graphical object to add
 

public void add(GObject gobj, double x, double y)

Adds the graphical object to this canvas and sets its location to the point (xy).
 
Usage: frame.add(gobj, x, y);
Parameters: 
gobj  The graphical object to add
x  The new x-coordinate for the object
y  The new y-coordinate for the object
 

public final void add(GObject gobj, Point pt)

Adds the graphical object to this canvas and sets its location to the specified point.
 
Usage: frame.add(gobj, pt);
Parameters: 
gobj  The graphical object to add
pt  A Point object giving the coordinates of the point
 

public GCanvas createGCanvas()

Creates the GCanvas used by the GFrame. Subclasses can override this method to create their own GCanvas types, but implementers must be careful to propagate the mouse events back to the frame so that the onMouseClicked style of interaction continues to work.

public MenuBar createMenuBar()

Creates the menu bar used by this GFrame. Subclasses can override this method to create their own menu bars. If this method returns null, no menu bar is created.
 
Usage: MenuBar mbar = frame.createMenuBar();
Returns: The menu bar to be used by this console frame, or null to eliminate the menu bar
 

public GObject getElement(int index)

Returns the graphical object at the specified index, numbering from back to front in the stacking order.
 
Usage: GObject gobj = frame.getElement(index);
Parameter: 
index  The index of the component to return
Returns: The graphical object at the specified index
 

public GObject getElementAt(double x, double y)

Returns the topmost graphical object that contains the point (x, y), or null if no such object exists.
 
Usage: GObject gobj = frame.getElementAt(x, y);
Parameters: 
x  The x-coordinate of the point being tested
y  The y-coordinate of the point being tested
Returns: The graphical object at the specified location, or null if no such object exists.
 

public int getElementCount()

Returns the number of graphical objects stored in this GCanvas.
 
Usage: int n = frame.getElementCount();
Returns: The number of graphical objects in this GCanvas
 

public GCanvas getGCanvas()

Returns the GCanvas object used by this frame.
 
Usage: GCanvas gc = frame.getGCanvas();
Returns: The GCanvas object used by the frame
 

public boolean isAutoRepaintEnabled()

Returns the current setting of the auto-repaint flag as described in setAutoRepaintEnabled.
 
Usage: if (frame.isAutoRepaintEnabled()) . . .
Returns: true if auto-repaint mode is enabled, and false otherwise
 

public Iterator iterator()

Returns an Iterator that cycles through the elements within this container in the default direction, which is from back to front. You can also run the iterator in the opposite direction by using the iterator(direction) form of this method.

Applets that want to run in browsers, however, should avoid using this method, because Iterator is not supported on 1.1 browsers. For maximum portability, you should rely instead on the getElementCount and getElement methods, which provide the same functionality in a browser-compatible way.

 
Usage: Iterator i = frame.iterator();
Returns: An Iterator ranging over the elements of the container from back to front
 

public Iterator iterator(int direction)

Returns an Iterator that cycles through the elements within this container in the specified direction, which must be one of the constants FRONT_TO_BACK or BACK_TO_FRONT.

  for (Iterator i = frame.iterator(direction); i.hasNext(); )

Applets that want to run in browsers, however, should avoid using this method, because Iterator is not supported on 1.1 browsers. For maximum portability, you should rely instead on the getElementCount and getElement methods, which provide the same functionality in a browser-compatible way.

 
Usage: Iterator i = frame.iterator(direction);
Returns: An Iterator ranging over the elements of the container in the specified direction
 

public void onMouseClicked(double x, double y)

This method is invoked automatically whenever a mouse click occurs in the canvas. Subclasses can override this method to respond to mouse clicks.
 
Usage: frame.onMouseClicked(x, y);
Parameters: 
x  The x-coordinate at which the mouse event occurred
y  The y-coordinate at which the mouse event occurred
 

public void onMouseDragged(double x, double y)

This method is invoked automatically whenever a mouse click occurs in the canvas. Subclasses can override this method to respond to mouse clicks.
 
Usage: frame.onMouseDragged(x, y);
Parameters: 
x  The x-coordinate at which the mouse event occurred
y  The y-coordinate at which the mouse event occurred
 

public void onMouseMoved(double x, double y)

This method is invoked automatically whenever a mouse click occurs in the canvas. Subclasses can override this method to respond to mouse clicks.
 
Usage: frame.onMouseMoved(x, y);
Parameters: 
x  The x-coordinate at which the mouse event occurred
y  The y-coordinate at which the mouse event occurred
 

public void onMousePressed(double x, double y)

This method is invoked automatically whenever a mouse click occurs in the canvas. Subclasses can override this method to respond to mouse clicks.
 
Usage: frame.onMousePressed(x, y);
Parameters: 
x  The x-coordinate at which the mouse event occurred
y  The y-coordinate at which the mouse event occurred
 

public void onMouseReleased(double x, double y)

This method is invoked automatically whenever a mouse click occurs in the canvas. Subclasses can override this method to respond to mouse clicks.
 
Usage: frame.onMouseReleased(x, y);
Parameters: 
x  The x-coordinate at which the mouse event occurred
y  The y-coordinate at which the mouse event occurred
 

public void remove(GObject gobj)

Removes a graphical object from this container.
 
Usage: frame.remove(gobj);
Parameter: 
gobj  The graphical object to remove
 

public void removeAll()

Removes all graphical objects from this container. Note that this definition overrides the Container version of removeAll, which is replaced by removeAllComponents.
 
Usage: frame.removeAll();
 

public void removeAllComponents()

Removes all components from this container.
 
Usage: frame.removeAllComponents();
 

public void setAutoRepaintEnabled(boolean state)

Changes the setting of the auto-repaint flag. By default, any change to a graphical object contained in this canvas automatically triggers a repaint of the canvas as a whole. While this behavior makes it much easier to use the package, it has the disadvantage that repaint requests come much more frequently than necessary. You can disable this feature by calling setAutoRepaintEnabled(false), but you must then make explicit calls to repaint() whenever you want to update the display. The advantage of this model is that you can then make many different changes and have them all appear at once with a single repaint call.
 
Usage: frame.setAutoRepaintEnabled(state);
Parameter: 
state  true to enable auto-repaint mode, and false to disable it