acm.program
Class Program

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
All Implemented Interfaces:
IOModel, ActionListener, KeyListener, MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Serializable, Runnable, EventListener, Accessible, RootPaneContainer
Direct Known Subclasses:
ConsoleProgram, DialogProgram, GraphicsProgram

public abstract class Program
extends JApplet
implements IOModel, Runnable, MouseListener, MouseMotionListener, KeyListener, ActionListener

This class is the superclass for all executable programs in the acm.program package. Its principal role is to unify the concepts of applets and applications in a single class, although it also provides applications with many other useful facilities not traditionally available in applications.

In many programming environments, objects that are specific instances of a Program subclass will run automatically without any special action on your part. For maximum portability, you might want to define a static main method as described in the comments for the standard implementation of main.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JApplet
JApplet.AccessibleJApplet
 
Nested classes/interfaces inherited from class java.applet.Applet
Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static String CENTER
          Constant specifying the center of the container
static String EAST
          Constant specifying the east edge of the container
static String NORTH
          Constant specifying the north edge of the container
static String SOUTH
          Constant specifying the south edge of the container
static String WEST
          Constant specifying the west edge of the container
 
Fields inherited from class javax.swing.JApplet
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
protected Program()
          This code initializes the program data structures.
 
Method Summary
 void actionPerformed(ActionEvent e)
          Called when a component (typically a button) is activated.
 void add(Component comp, String region, Object constraints)
          Adds the component to the specified border region with the indicated constraints object.
 void addActionListeners()
          Adds the program as an ActionListener to every button in the structure that does not have a listener already.
 void addActionListeners(ActionListener listener)
          Adds the specified listener to every button in the structure that does not have a listener already.
 void addExitHook(Object obj)
          Requests that the program call the exit method in the specified object before exiting.
protected  void addImpl(Component comp, Object constraints, int index)
          Adds the specified component to the content pane using the specified constraints and index.
protected  IOConsole createConsole()
          Creates the console used by the ConsoleProgram.
protected  IODialog createDialogIO()
          Creates the dialog used for interaction (primarily by the DialogProgram class).
protected  ProgramMenuBar createMenuBar()
          Creates a menu bar for use with the program.
protected static HashMap<String,String> createParameterTable(String[] args)
          Creates a hash table containing the parameters specified in the argument list.
protected  JFrame createProgramFrame()
          Creates the frame containing the program.
 void destroy()
          Called when the program has been told to destroy itself.
protected  void endHook()
          Performs class-specific cleanup for the program just after it finishes.
 void exit()
          Exits from the program.
protected  AppletStub getAppletStub()
          Retrieves the applet stub.
protected  String[] getArgumentArray()
          Retrieves the array of arguments passed in from the command line, or null if no arguments are available.
protected  Component getBorder(String side)
          Returns the component installed as a border on the specified side, which must be one of the constants from BorderLayout (NORTH, SOUTH, EAST, WEST).
 Dimension getCentralRegionSize()
          Returns the size of the central region.
 IOConsole getConsole()
          Returns the console associated with this program.
 IODialog getDialog()
          Returns the dialog used for user interaction.
 int getHeight()
          Returns the height of the central region.
 IOModel getInputModel()
          Returns the IOModel used for program input, which will ordinarily be the console.
 LayoutManager getLayout()
          Gets the layout manager for the central region of the content pane.
 Thread getMainThread()
          Returns the thread that is running the main program.
 ProgramMenuBar getMenuBar()
          Returns the menu bar associated with this program.
 IOModel getOutputModel()
          Returns the IOModel used for program output, which will ordinarily be the console.
 String getParameter(String name)
          Returns the parameter associated with name.
protected  HashMap<String,String> getParameterTable()
          Retrieves the parameter table.
 Dimension getPreferredSize()
          Returns the preferred size of the content pane.
 BufferedReader getReader()
          Returns a BufferedReader whose input comes from the console.
 JPanel getRegionPanel(String region)
          Gets the JPanel for the specified region.
protected  Object getStartupObject()
          Retrieves the object that was created when this program was started if that object is something other than a Program.
 String getTitle()
          Gets the title of this program.
 int getWidth()
          Returns the width of the central region.
 PrintWriter getWriter()
          Returns a PrintWriter whose output is directed to the console.
 void init()
          Specifies the code to be executed as startup time before the run method is called.
 boolean isAppletMode()
          Returns true if this program is running as an applet in a browser.
protected  boolean isStarted()
          Checks to see whether this program has started, usually by checking to see whether some pane exists.
 void keyPressed(KeyEvent e)
          Called when a key is pressed.
 void keyReleased(KeyEvent e)
          Called when a key is released.
 void keyTyped(KeyEvent e)
          Called when a key is typed (i.e., pressed and released).
static void main(String[] args)
          Every application must either contain a "Main-Class" entry in its manifest file or include a main method that looks like this, where MyClass is the name of the program class:
 boolean menuAction(ActionEvent e)
          Called whenever a program action is detected in the menu bar.
 void mouseClicked(MouseEvent e)
          Called when the mouse is clicked.
 void mouseDragged(MouseEvent e)
          Called when the mouse is dragged with the button down.
 void mouseEntered(MouseEvent e)
          Called when the mouse enters the source (which may be either a component or a GObject).
 void mouseExited(MouseEvent e)
          Called when the mouse exits the source (which may be either a component or a GObject).
 void mouseMoved(MouseEvent e)
          Called when the mouse is moved.
 void mousePressed(MouseEvent e)
          Called when the mouse button is pressed.
 void mouseReleased(MouseEvent e)
          Called when the mouse button is released.
 void pause(double milliseconds)
          Delays the calling thread for the specified time, which is expressed in milliseconds.
 void print(boolean x)
          Makes sure that print can display a boolean.
 void print(char x)
          Makes sure that print can display a char.
 void print(double x)
          Makes sure that print can display a double.
 void print(float x)
          Makes sure that print can display a float.
 void print(int x)
          Makes sure that print can display an int.
 void print(long x)
          Makes sure that print can display a long.
 void print(Object x)
          Makes sure that print can display an Object.
 void print(String value)
          Displays the argument value on the console, leaving the cursor at the end of the output.
 void println()
          Advances the console cursor to the beginning of the next line.
 void println(boolean x)
          Makes sure that println can display a boolean.
 void println(char x)
          Makes sure that println can display a char.
 void println(double x)
          Makes sure that println can display a double.
 void println(float x)
          Makes sure that println can display a float.
 void println(int x)
          Makes sure that println can display an int.
 void println(long x)
          Makes sure that println can display a long.
 void println(Object x)
          Makes sure that println can display an Object.
 void println(String value)
          Displays the argument value on the console and then advances the cursor to the beginning of the next line.
 boolean readBoolean()
          Reads and returns a boolean value (true or false).
 boolean readBoolean(String prompt)
          Prompts the user to enter a boolean value, which is returned as the value of this method.
 boolean readBoolean(String prompt, String trueLabel, String falseLabel)
          Prompts the user to enter a boolean value, which is matched against the labels provided.
 double readDouble()
          Reads and returns a double-precision value from the user.
 double readDouble(double low, double high)
          Reads and returns a double-precision value from the user, which is constrained to be within the specified inclusive range.
 double readDouble(String prompt)
          Prompts the user to enter an double-precision number, which is then returned as the value of this method.
 double readDouble(String prompt, double low, double high)
          Prompts the user to enter an double-precision number, which is then returned as the value of this method.
 int readInt()
          Reads and returns an integer value from the user.
 int readInt(int low, int high)
          Reads and returns an integer value from the user, which is constrained to be within the specified inclusive range.
 int readInt(String prompt)
          Prompts the user to enter an integer, which is then returned as the value of this method.
 int readInt(String prompt, int low, int high)
          Prompts the user to enter an integer, which is then returned as the value of this method.
 String readLine()
          Reads and returns a line of input from the console.
 String readLine(String prompt)
          Prompts the user for a line of input.
 void remove(Component comp)
          Removes the specified component from the central region.
 void remove(int index)
          Removes the component at the specified index from the central region.
 void removeAll()
          Removes all components from the central region.
 void repaint()
          Forwards repaint to the content pane.
 void run()
          Specifies the code to be executed as the program runs.
protected  void runHook()
          Calls the run method in the program.
protected  void setAppletStub(AppletStub stub)
          Sets the applet stub for this program in a way that makes it possible for clients to retrieve it.
 void setBackground(Color color)
          Sets the background for the central region of the content pane.
 void setConsole(IOConsole console)
          Sets the console associated with this program.
 void setDialog(IODialog dialog)
          Sets the dialog associated with this program.
 void setInputModel(IOModel io)
          Sets the input model associated with this program.
 void setLayout(LayoutManager layout)
          Sets the layout manager for the central region of the content pane.
 void setOutputModel(IOModel io)
          Sets the output model associated with this program.
 void setParameter(String name, String value)
          Sets a new value for the named parameter.
protected  void setParameterTable(HashMap<String,String> ht)
          Sets the parameter table for this program.
protected  void setStartupObject(Object obj)
          Sets the object that is created when the program is started so that it can be retrieved later by getStartupObject.
 void setTitle(String title)
          Sets the title of this program.
 void showErrorMessage(String msg)
          Displays the error message in the standard output model.
 void start()
          Starts the program when it is running in application mode.
 void start(String[] args)
          Starts the program using the specified argument list.
protected  void startHook()
          Performs class-specific initialization for the program just before it starts.
protected  void startRun()
          Initializes and runs the run method.
 void validate()
          Forwards validate to the content pane.
 
Methods inherited from class javax.swing.JApplet
createRootPane, getAccessibleContext, getContentPane, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.applet.Applet
getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, stop
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getListeners, getMaximumSize, getMinimumSize, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CENTER

public static final String CENTER
Constant specifying the center of the container

See Also:
Constant Field Values

EAST

public static final String EAST
Constant specifying the east edge of the container

See Also:
Constant Field Values

NORTH

public static final String NORTH
Constant specifying the north edge of the container

See Also:
Constant Field Values

SOUTH

public static final String SOUTH
Constant specifying the south edge of the container

See Also:
Constant Field Values

WEST

public static final String WEST
Constant specifying the west edge of the container

See Also:
Constant Field Values
Constructor Detail

Program

protected Program()
This code initializes the program data structures.

Method Detail

actionPerformed

public void actionPerformed(ActionEvent e)
Called when a component (typically a button) is activated.

Specified by:
actionPerformed in interface ActionListener

add

public void add(Component comp,
                String region,
                Object constraints)
Adds the component to the specified border region with the indicated constraints object.

Parameters:
comp - The component to be added
region - The region of the window (NORTH, SOUTH, EAST, WEST, or CENTER)
constraints - The constraints object

addActionListeners

public void addActionListeners()
Adds the program as an ActionListener to every button in the structure that does not have a listener already.


addActionListeners

public void addActionListeners(ActionListener listener)
Adds the specified listener to every button in the structure that does not have a listener already.

Parameters:
listener - The ActionListener to be added

addExitHook

public void addExitHook(Object obj)
Requests that the program call the exit method in the specified object before exiting.


addImpl

protected void addImpl(Component comp,
                       Object constraints,
                       int index)
Adds the specified component to the content pane using the specified constraints and index.

Overrides:
addImpl in class JApplet

createConsole

protected IOConsole createConsole()
Creates the console used by the ConsoleProgram. Subclasses can override this method to create their own console types.

Returns:
The console to be used by the program

createDialogIO

protected IODialog createDialogIO()
Creates the dialog used for interaction (primarily by the DialogProgram class). Subclasses can override this method to create their own dialog types.

Returns:
The dialog to be used by the program

createMenuBar

protected ProgramMenuBar createMenuBar()
Creates a menu bar for use with the program.

Returns:
A menu bar for use with this Program

createParameterTable

protected static HashMap<String,String> createParameterTable(String[] args)
Creates a hash table containing the parameters specified in the argument list. Parameters are taken to be any argument that matches the template

name=value All other arguments are collected as a tab-separated string and placed in an entry under the key "ARGS". All named parameters are converted to lower case to preserve the case-insensitive semantics of getParameter.

Parameters:
args - The array of strings passed to the application
Returns:
A HashMap containing the parameter bindings

createProgramFrame

protected JFrame createProgramFrame()
Creates the frame containing the program.

Returns:
The newly allocated Frame object

destroy

public void destroy()
Called when the program has been told to destroy itself. The code here stops the main thread and any animators that have been initiated by this applet.

Overrides:
destroy in class Applet

endHook

protected void endHook()
Performs class-specific cleanup for the program just after it finishes.


exit

public void exit()
Exits from the program. Subclasses should override this method if they need to perform any actions before shutting down the program, such as asking the user to save any unsaved files. Any clients that do override this method should call super.exit() at the end of their processing.


getAppletStub

protected AppletStub getAppletStub()
Retrieves the applet stub.

Returns:
The applet stub

getArgumentArray

protected String[] getArgumentArray()
Retrieves the array of arguments passed in from the command line, or null if no arguments are available.

Returns:
The array of command-line arguments

getBorder

protected Component getBorder(String side)
Returns the component installed as a border on the specified side, which must be one of the constants from BorderLayout (NORTH, SOUTH, EAST, WEST).

Parameters:
side - The side (NORTH, SOUTH, EAST, or WEST)
Returns:
The component used as a border on the specified side

getCentralRegionSize

public Dimension getCentralRegionSize()
Returns the size of the central region. If the content pane has not been validated, this method computes its preferred size by subtracting the sizes required for the side panels from the size of the entire frame.

Returns:
The size of the central region

getConsole

public IOConsole getConsole()
Returns the console associated with this program.

Returns:
The IOConsole object used for this program

getDialog

public IODialog getDialog()
Returns the dialog used for user interaction.

Returns:
The IODialog object used for this program

getHeight

public int getHeight()
Returns the height of the central region.

Overrides:
getHeight in class Component
Returns:
The height of the central region

getInputModel

public IOModel getInputModel()
Returns the IOModel used for program input, which will ordinarily be the console.

Returns:
The IOModel used for program input

getLayout

public LayoutManager getLayout()
Gets the layout manager for the central region of the content pane.

Overrides:
getLayout in class Container
Returns:
The active layout manager

getMainThread

public Thread getMainThread()
Returns the thread that is running the main program.

Returns:
The thread that is running the main program, if any

getMenuBar

public ProgramMenuBar getMenuBar()
Returns the menu bar associated with this program. Note that this menu bar cannot be set by clients, although it can be changed initially by overriding the createMenuBar factory method.

Returns:
The menu bar in use for this program

getOutputModel

public IOModel getOutputModel()
Returns the IOModel used for program output, which will ordinarily be the console.

Returns:
The IOModel used for program output

getParameter

public String getParameter(String name)
Returns the parameter associated with name.

Overrides:
getParameter in class Applet
Parameters:
name - The name of the parameter
Returns:
The value associated with the parameter, or null if none

getParameterTable

protected HashMap<String,String> getParameterTable()
Retrieves the parameter table.

Returns:
The parameter table

getPreferredSize

public Dimension getPreferredSize()
Returns the preferred size of the content pane.

Overrides:
getPreferredSize in class Container
Returns:
The preferred size of the content pane

getReader

public BufferedReader getReader()
Returns a BufferedReader whose input comes from the console.

Returns:
A Reader for use with this console

getRegionPanel

public JPanel getRegionPanel(String region)
Gets the JPanel for the specified region.

Parameters:
region - The region of the window (NORTH, SOUTH, EAST, WEST, or CENTER)
Returns:
The JPanel for that subregion

getStartupObject

protected Object getStartupObject()
Retrieves the object that was created when this program was started if that object is something other than a Program. In the normal case of running a Program object, this method will return null.

Returns:
The startup object

getTitle

public String getTitle()
Gets the title of this program.

Returns:
The title in use for this program

getWidth

public int getWidth()
Returns the width of the central region.

Overrides:
getWidth in class Component
Returns:
The width of the central region

getWriter

public PrintWriter getWriter()
Returns a PrintWriter whose output is directed to the console.

Returns:
A PrintWriter for use with this console

init

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.

Overrides:
init in class Applet

isAppletMode

public boolean isAppletMode()
Returns true if this program is running as an applet in a browser.

Returns:
true if this program is running as an applet, false otherwise

isStarted

protected boolean isStarted()
Checks to see whether this program has started, usually by checking to see whether some pane exists. Subclasses can override this method to ensure that their structures are visible before proceeding.


keyPressed

public void keyPressed(KeyEvent e)
Called when a key is pressed.

Specified by:
keyPressed in interface KeyListener

keyReleased

public void keyReleased(KeyEvent e)
Called when a key is released.

Specified by:
keyReleased in interface KeyListener

keyTyped

public void keyTyped(KeyEvent e)
Called when a key is typed (i.e., pressed and released).

Specified by:
keyTyped in interface KeyListener

main

public static void main(String[] args)
Every application must either contain a "Main-Class" entry in its manifest file or include a main method that looks like this, where MyClass is the name of the program class:


      public static void main(String[] args) {
         new MyClass().start();
      }
 

If the program needs the command line arguments, the args array can be passed to the start method and then retrieved using the getArgumentArray method.

Parameters:
args - An array of string arguments

menuAction

public boolean menuAction(ActionEvent e)
Called whenever a program action is detected in the menu bar. Subclasses can override this method to extend the set of menu commands recognized even in the absence of a component with keyboard focus.


mouseClicked

public void mouseClicked(MouseEvent e)
Called when the mouse is clicked. A call to mouseClicked is always preceded by both a mousePressed and a mouseReleased event for the same source.

Specified by:
mouseClicked in interface MouseListener

mouseDragged

public void mouseDragged(MouseEvent e)
Called when the mouse is dragged with the button down. Java makes several guarantees about dragging. First, a mouseDragged call is always preceded by a mousePressed call for the same source. If the mouse is pressed elsewhere and then enters a source with the button down, no drag event occurs. Moreover, once the mouse button goes down in a particular source, only that source will receive mouse events until the button goes up. Those events, moreover, are reported even in the mouse travels outside the domain of the object.

Specified by:
mouseDragged in interface MouseMotionListener

mouseEntered

public void mouseEntered(MouseEvent e)
Called when the mouse enters the source (which may be either a component or a GObject).

Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Called when the mouse exits the source (which may be either a component or a GObject).

Specified by:
mouseExited in interface MouseListener

mouseMoved

public void mouseMoved(MouseEvent e)
Called when the mouse is moved.

Specified by:
mouseMoved in interface MouseMotionListener

mousePressed

public void mousePressed(MouseEvent e)
Called when the mouse button is pressed.

Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
Called when the mouse button is released.

Specified by:
mouseReleased in interface MouseListener

pause

public void pause(double milliseconds)
Delays the calling thread for the specified time, which is expressed in milliseconds. Unlike Thread.sleep, this method never throws an exception.

Parameters:
milliseconds - The sleep time in milliseconds

print

public final void print(boolean x)
Makes sure that print can display a boolean.

Specified by:
print in interface IOModel

print

public final void print(char x)
Makes sure that print can display a char.

Specified by:
print in interface IOModel

print

public final void print(double x)
Makes sure that print can display a double.

Specified by:
print in interface IOModel

print

public final void print(float x)
Makes sure that print can display a float.

Specified by:
print in interface IOModel

print

public final void print(int x)
Makes sure that print can display an int.

Specified by:
print in interface IOModel

print

public final void print(long x)
Makes sure that print can display a long.

Specified by:
print in interface IOModel

print

public final void print(Object x)
Makes sure that print can display an Object.

Specified by:
print in interface IOModel

print

public void print(String value)
Displays the argument value on the console, leaving the cursor at the end of the output. The print method is overloaded so that value can be of any type.

Specified by:
print in interface IOModel
Parameters:
value - The value to be displayed

println

public void println()
Advances the console cursor to the beginning of the next line.

Specified by:
println in interface IOModel

println

public final void println(boolean x)
Makes sure that println can display a boolean.

Specified by:
println in interface IOModel

println

public final void println(char x)
Makes sure that println can display a char.

Specified by:
println in interface IOModel

println

public final void println(double x)
Makes sure that println can display a double.

Specified by:
println in interface IOModel

println

public final void println(float x)
Makes sure that println can display a float.

Specified by:
println in interface IOModel

println

public final void println(int x)
Makes sure that println can display an int.

Specified by:
println in interface IOModel

println

public final void println(long x)
Makes sure that println can display a long.

Specified by:
println in interface IOModel

println

public final void println(Object x)
Makes sure that println can display an Object.

Specified by:
println in interface IOModel

println

public void println(String value)
Displays the argument value on the console and then advances the cursor to the beginning of the next line. The println method is overloaded so that value can be of any type.

Specified by:
println in interface IOModel
Parameters:
value - The value to be displayed

readBoolean

public final boolean readBoolean()
Reads and returns a boolean value (true or false). The input must match one of these strings, ignoring case. If the user types a value that is not one of these possibilities, the method ordinarily offers the user a chance to reenter the data, although this behavior can be changed using the setExceptionOnError method.

Specified by:
readBoolean in interface IOModel
Returns:
The value of the input interpreted as a boolean value

readBoolean

public final boolean readBoolean(String prompt)
Prompts the user to enter a boolean value, which is returned as the value of this method. If the user types a value that is not a legal boolean value, the method ordinarily offers the user a chance to reenter the data, although this behavior can be changed using the setExceptionOnError method.

Specified by:
readBoolean in interface IOModel
Parameters:
prompt - The prompt string to display to the user
Returns:
The value of the input interpreted as a boolean value

readBoolean

public boolean readBoolean(String prompt,
                           String trueLabel,
                           String falseLabel)
Prompts the user to enter a boolean value, which is matched against the labels provided. If the user enters a value that is not one of the two choices, readBoolean ordinarily offers the user a chance to reenter the data, although this behavior can be changed using the setExceptionOnError method.

Specified by:
readBoolean in interface IOModel
Parameters:
prompt - The prompt string to display to the user
trueLabel - The string used to indicate true
falseLabel - The string used to indicate false
Returns:
The value of the input interpreted as a boolean value

readDouble

public final double readDouble()
Reads and returns a double-precision value from the user. If the user types a value that is not a legal number, the method ordinarily offers the user a chance to reenter the data, although this behavior can be changed using the setExceptionOnError method.

Specified by:
readDouble in interface IOModel
Returns:
The value of the input interpreted as a double

readDouble

public final double readDouble(double low,
                               double high)
Reads and returns a double-precision value from the user, which is constrained to be within the specified inclusive range. If the user types a value that is not a legal number, the method ordinarily offers the user a chance to reenter the data, although this behavior can be changed using the setExceptionOnError method.

Specified by:
readDouble in interface IOModel
Parameters:
low - The lowest value in the permitted range
high - The highest value in the permitted range
Returns:
The value of the input interpreted as a double

readDouble

public final double readDouble(String prompt)
Prompts the user to enter an double-precision number, which is then returned as the value of this method. If the user types a value that is not a legal number, the method ordinarily offers the user a chance to reenter the data, although this behavior can be changed using the setExceptionOnError method.

Specified by:
readDouble in interface IOModel
Parameters:
prompt - The prompt string to display to the user
Returns:
The value of the input interpreted as a double

readDouble

public double readDouble(String prompt,
                         double low,
                         double high)
Prompts the user to enter an double-precision number, which is then returned as the value of this method. The value must be within the inclusive range between low and high. If the user types a value that is not a legal number, the method ordinarily offers the user a chance to reenter the data, although this behavior can be changed using the setExceptionOnError method.

Specified by:
readDouble in interface IOModel
Parameters:
prompt - The prompt string to display to the user
low - The lowest value in the permitted range
high - The highest value in the permitted range
Returns:
The value of the input interpreted as a double

readInt

public final int readInt()
Reads and returns an integer value from the user. If the user types a value that is not a legal integer, the method ordinarily offers the user a chance to reenter the data, although this behavior can be changed using the setExceptionOnError method.

Specified by:
readInt in interface IOModel
Returns:
The value of the input interpreted as a decimal integer

readInt

public final int readInt(int low,
                         int high)
Reads and returns an integer value from the user, which is constrained to be within the specified inclusive range. If the user types a value that is not a legal integer, the method ordinarily offers the user a chance to reenter the data, although this behavior can be changed using the setExceptionOnError method.

Specified by:
readInt in interface IOModel
Parameters:
low - The lowest value in the permitted range
high - The highest value in the permitted range
Returns:
The value of the input interpreted as a decimal integer

readInt

public final int readInt(String prompt)
Prompts the user to enter an integer, which is then returned as the value of this method. If the user types a value that is not a legal integer, the method ordinarily offers the user a chance to reenter the data, although this behavior can be changed using the setExceptionOnError method.

Specified by:
readInt in interface IOModel
Parameters:
prompt - The prompt string to display to the user
Returns:
The value of the input interpreted as a decimal integer

readInt

public int readInt(String prompt,
                   int low,
                   int high)
Prompts the user to enter an integer, which is then returned as the value of this method. The value must be within the inclusive range between low and high. If the user types a value that is not a legal integer or is outside the specified range, the method ordinarily offers the user a chance to reenter the data, although this behavior can be changed using the setExceptionOnError method.

Specified by:
readInt in interface IOModel
Parameters:
prompt - The prompt string to display to the user
low - The lowest value in the permitted range
high - The highest value in the permitted range
Returns:
The value of the input interpreted as a decimal integer

readLine

public final String readLine()
Reads and returns a line of input from the console. The end-of-line characters that terminate the input are not included in the returned string.

Specified by:
readLine in interface IOModel
Returns:
The next line of input as a String

readLine

public String readLine(String prompt)
Prompts the user for a line of input. The end-of-line characters that terminate the input are not included in the returned string.

Specified by:
readLine in interface IOModel
Parameters:
prompt - The prompt string to display to the user
Returns:
The next line of input as a String

remove

public void remove(Component comp)
Removes the specified component from the central region.

Overrides:
remove in class JApplet
Parameters:
comp - The component to remove

remove

public void remove(int index)
Removes the component at the specified index from the central region.

Overrides:
remove in class Container
Parameters:
index - The index position of the component to remove

removeAll

public void removeAll()
Removes all components from the central region.

Overrides:
removeAll in class Container

repaint

public void repaint()
Forwards repaint to the content pane.

Overrides:
repaint in class Component

run

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

runHook

protected void runHook()
Calls the run method in the program. Subclasses can override this method to transfer control somewhere else.


setAppletStub

protected void setAppletStub(AppletStub stub)
Sets the applet stub for this program in a way that makes it possible for clients to retrieve it.

Parameters:
stub - The applet stub

setBackground

public void setBackground(Color color)
Sets the background for the central region of the content pane.

Overrides:
setBackground in class Component
Parameters:
color - The new background color

setConsole

public void setConsole(IOConsole console)
Sets the console associated with this program.

Parameters:
console - The IOConsole object used for this program

setDialog

public void setDialog(IODialog dialog)
Sets the dialog associated with this program.

Parameters:
dialog - The IODialog object used for this program

setInputModel

public void setInputModel(IOModel io)
Sets the input model associated with this program.

Parameters:
io - The input model used for this program

setLayout

public void setLayout(LayoutManager layout)
Sets the layout manager for the central region of the content pane.

Overrides:
setLayout in class JApplet
Parameters:
layout - The layout manager to use

setOutputModel

public void setOutputModel(IOModel io)
Sets the output model associated with this program.

Parameters:
io - The IOModel object used as the output model

setParameter

public void setParameter(String name,
                         String value)
Sets a new value for the named parameter.

Parameters:
name - The name of the parameter
value - The new value

setParameterTable

protected void setParameterTable(HashMap<String,String> ht)
Sets the parameter table for this program.

Parameters:
ht - The parameter table

setStartupObject

protected void setStartupObject(Object obj)
Sets the object that is created when the program is started so that it can be retrieved later by getStartupObject.

Parameters:
obj - The startup object

setTitle

public void setTitle(String title)
Sets the title of this program. The title appears in the title bar when the program is running as an application.

Parameters:
title - The title for this program

showErrorMessage

public void showErrorMessage(String msg)
Displays the error message in the standard output model.

Specified by:
showErrorMessage in interface IOModel
Parameters:
msg - The error msg to be displayed

start

public final void start()
Starts the program when it is running in application mode. Note that this overloads the start method in Applet and therefore will be called as part of applet startup.

Overrides:
start in class Applet

start

public void start(String[] args)
Starts the program using the specified argument list.

Parameters:
args - An array of strings passed to the program

startHook

protected void startHook()
Performs class-specific initialization for the program just before it starts.


startRun

protected void startRun()
Initializes and runs the run method.


validate

public void validate()
Forwards validate to the content pane.

Overrides:
validate in class Container