acm.program
Class GraphicsProgram

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by javax.swing.JApplet
                      extended by acm.program.Program
                          extended by acm.program.GraphicsProgram

public abstract class GraphicsProgram
extends Program

This class is a standard subclass of Program whose principal window is used for drawing graphics.


Field Summary
 
Method Summary
 void add(Component comp, double x, double y)
Adds the component to the canvas and sets its location to the point (xy).
 void add(Component comp, GPoint pt)
Adds the component to the canvas and sets its location to the specified point.
 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 the canvas and sets its location to the point (xy).
 void add(GObject gobj, GPoint pt)
Adds the graphical object to the canvas and sets its location to the specified point.
 void addKeyListeners()
Adds the program as a KeyListener to the canvas.
 void addKeyListeners(KeyListener listener)
Adds the specified listener as a KeyListener to the canvas.
 void addMouseListeners()
Adds the program as both a MouseListener and MouseMotionListener to the canvas.
 void addMouseListeners(EventListener listener)
Adds the specified listener as a MouseListener and/or MouseMotionListener, as appropriate, to the canvas.
 GObject getElement(int index)
Returns the graphical object at the specified index, numbering from back to front in the the z dimension.
 GObject getElementAt(double x, double y)
Returns the topmost graphical object that contains the point (x, y), or null if no such object exists.
 GObject getElementAt(GPoint pt)
Returns the topmost graphical object that contains the specified point, 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 program.
 void init()
Specifies the code to be executed as startup time before the run method is called.
 Iterator<GObject> iterator()
Returns an Iterator that cycles through the elements within this container in the default direction, which is from back to front.
 Iterator<GObject> 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 from the GContainer interface.
 void remove(GObject gobj)
Removes a graphical object from this container.
 void removeAll()
Removes all graphical objects from this container.
 void run()
Specifies the code to be executed as the program runs.
 void waitForClick()
Waits for a mouse click in the window before proceeding.
 
Inherited Method Summary
IOConsolegetConsole()
Returns the console associated with this program.
IODialoggetDialog()
Returns the dialog used for user interaction.
BufferedReadergetReader()
Returns a BufferedReader whose input comes from the console.
StringgetTitle()
Gets the title of this program.
PrintWritergetWriter()
Returns a PrintWriter whose output is directed to the console.
voidpause(double milliseconds)
Delays the calling thread for the specified time, which is expressed in milliseconds.
voidprint(String value)
Displays the argument value on the console, leaving the cursor at the end of the output.
voidprintln()
Advances the console cursor to the beginning of the next line.
voidprintln(String value)
Displays the argument value on the console and then advances the cursor to the next line.
booleanreadBoolean()
Reads and returns a boolean value (true or false).
booleanreadBoolean(String prompt)
Prompts the user to enter a boolean value.
booleanreadBoolean(String prompt, String trueLabel, String falseLabel)
Prompts the user to enter a boolean value, which is matched against the labels provided.
doublereadDouble()
Reads and returns a double-precision value from the user.
doublereadDouble(String prompt)
Prompts the user to enter a double-precision number, which is returned as the value of this method.
intreadInt()
Reads and returns an integer value from the user.
intreadInt(String prompt)
Prompts the user to enter an integer.
StringreadLine()
Reads and returns a line of input from the console.
StringreadLine(String prompt)
Prompts the user for a line of input.
voidsetTitle(String title)
Sets the title of this program.
 

Method Detail

public final void add(Component comp, double x, double y)

Adds the component to the canvas and sets its location to the point (xy).

 
Usage: add(comp, x, y); 
Parameters: 
comp  The component to add
 The new x-coordinate for the object
 The new y-coordinate for the object
 


public final void add(Component comp, GPoint pt)

Adds the component to the canvas and sets its location to the specified point.

 
Usage: add(comp, pt); 
Parameters: 
comp  The component to add
pt  A GPoint object giving the coordinates of the point
 


public void add(GObject gobj)

Adds a new graphical object to this container.

 
Usage: add(gobj); 
Parameter: 
gobj  The graphical object to add
 


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

Adds the graphical object to the canvas and sets its location to the point (xy).

 
Usage: add(gobj, x, y); 
Parameters: 
gobj  The graphical object to add
 The new x-coordinate for the object
 The new y-coordinate for the object
 


public final void add(GObject gobj, GPoint pt)

Adds the graphical object to the canvas and sets its location to the specified point.

 
Usage: add(gobj, pt); 
Parameters: 
gobj  The graphical object to add
pt  The new coordinates of the point
 


public void addKeyListeners()

Adds the program as a KeyListener to the canvas.

 
Usage: addKeyListeners(); 
 


public void addKeyListeners(KeyListener listener)

Adds the specified listener as a KeyListener to the canvas.

 
Usage: addKeyListeners(listener); 
Parameter: 
listener  A KeyListener object
 


public void addMouseListeners()

Adds the program as both a MouseListener and MouseMotionListener to the canvas.

 
Usage: addMouseListeners(); 
 


public void addMouseListeners(EventListener listener)

Adds the specified listener as a MouseListener and/or MouseMotionListener, as appropriate, to the canvas.

 
Usage: addMouseListeners(listener); 
Parameter: 
listener  A listener object that is either a MouseListener, a MouseMotionListener, or both
 


public GObject getElement(int index)

Returns the graphical object at the specified index, numbering from back to front in the the z dimension.

 
Usage: GObject gobj = 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 = program.getElementAt(x, y); 
Parameters: 
 The x-coordinate of the point being tested
 The y-coordinate of the point being tested
Returns: The graphical object at the specified location, or null if no such object exists.
 


public final GObject getElementAt(GPoint pt)

Returns the topmost graphical object that contains the specified point, or null if no such object exists.

 
Usage: GObject gobj = program.getElementAt(pt); 
Parameter: 
pt  The coordinates 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 = getElementCount(); 
Returns: The number of graphical objects in this GCanvas
 


public GCanvas getGCanvas()

Returns the GCanvas object used by this program.

 
Usage: GCanvas gc = getGCanvas(); 
Returns: The GCanvas object used by the program
 


public void init()

Specifies the code to be executed as startup time before the run method is called. Subclasses can override this method to perform any initialization code that would ordinarily be included in an applet init method. In general, subclasses will override init in GUI-based programs where the program simply sets up an initial state and then waits for events from the user. The run method is required for applications in which there needs to be some control thread while the program runs, as in a typical animation.

 
Usage: program.init(); 
 


public Iterator<GObject> 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 = iterator(); 
Returns: An Iterator ranging over the elements of the container from back to front
 


public Iterator<GObject> 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 from the GContainer interface.

for (Iterator<GObject> i = 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 = iterator(direction); 
Returns: An Iterator ranging over the elements of the container in the specified direction
 


public void remove(GObject gobj)

Removes a graphical object from this container.

 
Usage: 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: removeAll(); 
 


public void run()

Specifies the code to be executed as the program runs. The run method is required for applications that have a thread of control that runs even in the absence of user actions, such as a program that uses console interation or that involves animation. GUI-based programs that operate by setting up an initial configuration and then wait for user events usually do not specify a run method and supply a new definition for init instead.

Specified by:
run in interface Runnable

public void waitForClick()

Waits for a mouse click in the window before proceeding.

 
Usage: waitForClick();