acm.program
Class ConsoleProgram

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.ConsoleProgram

public abstract class ConsoleProgram
extends Program

This class is a standard subclass of Program that installs a console in the window.


Field Summary
 
Constructor Summary
ConsoleProgram()
Creates a new console program.
 
Method Summary
 void init()
Specifies the code to be executed as startup time before the run method is called.
 void run()
Specifies the code to be executed as the program runs.
 void setFont(Font font)
Sets the font for the console.
 void setFont(String str)
Sets the font used for the console as specified by the string str, which is interpreted in the style of Font.decode.
 
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.
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.
 

Constructor Detail

public ConsoleProgram()

Creates a new console program.

 
Usage: ConsoleProgram program = new ConsoleProgram(); 
 

Method Detail

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 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 setFont(Font font)

Sets the font for the console.

 
Usage: program.setFont(font); 
Parameter: 
font  The new font
 


public void setFont(String str)

Sets the font used for the console as specified by the string str, which is interpreted in the style of Font.decode. The usual format of the font string is

family-style-size

where both style and size are optional. If any of these parts are specified as an asterisk, the existing value is retained.


 
Usage: program.setFont(str); 
Parameter: 
str  A String specifying the new font