Class ConsoleParent

java.lang.Object
  extended by ConsoleParent
All Implemented Interfaces:
ActionListener, FocusListener, KeyListener, WindowListener, EventListener
Direct Known Subclasses:
Console

abstract class ConsoleParent
extends Object
implements ActionListener, FocusListener, KeyListener, WindowListener


Field Summary
protected static int BUFFER_SIZE
           
(package private)  ConsoleCanvas consoleCanvas
          The drawing surface.
protected  Panel consoleCanvasPanelInner
           
protected static int DEFAULT_COLUMNS
           
protected static int DEFAULT_FONT_SIZE
           
protected static int DEFAULT_ROWS
           
protected static String DEFAULT_TITLE
           
protected static int EMPTY_BUFFER
           
protected  boolean eofReached
           
protected  char[] kbdBuffer
           
protected  int kbdBufferHead
           
protected  int kbdBufferTail
           
protected  char[] lineBuffer
           
protected  int lineBufferHead
           
protected  int lineBufferTail
           
protected  int maxCol
           
protected  int maxRow
           
protected static String PRINT_COMMAND
           
protected static String QUIT_COMMAND
           
protected static String SAVE_COMMAND
           
protected static int TAB_SIZE
           
protected  int ungotChar
           
protected  ConsoleFrame window
           
 
Constructor Summary
ConsoleParent()
           
 
Method Summary
 void actionPerformed(ActionEvent e)
          Quits the program, saves the contents of the window, or prints the contents of the window, depending on which button is pressed.
 void close()
          Closes the console window.
protected  void enableButtons(boolean enable)
          Enables or disables all the buttons in the Console.
 void focusGained(FocusEvent e)
          Sets the focus to the invisible button and then the console canvas.
 void focusLost(FocusEvent e)
          Does nothing.
protected  void initialize(int rows, int columns, int fontSize, String title)
          Initializes the window.
 void keyPressed(KeyEvent e)
          Places a keystroke in the keyboard buffer.
 void keyReleased(KeyEvent e)
          Does nothing.
 void keyTyped(KeyEvent e)
          Does nothing.
protected  void mainStopped()
          This method is invoked if the "main" method appears to have stopped executing.
 void print(boolean value)
          Writes the text representation of a boolean to the Console.
 void print(boolean value, int fieldSize)
          Writes the text representation of a boolean to the Console with a specified field size.
 void print(byte number)
          Writes the text representation of an 8-bit integer (a "byte") to the Console.
 void print(byte number, int fieldSize)
          Writes the text representation of an 8-bit integer (a "byte") to the Console with a specified field size.
 void print(char ch)
          Writes a character to the Console.
 void print(char ch, int fieldSize)
          Writes a character to the Console with a specified field size..
 void print(double number)
          Writes a double precision floating point number (a "double") to the Console.
 void print(double number, int fieldSize)
          Writes a double precision floating point number (a "double") to the Console with a specified field size.
 void print(double number, int fieldSize, int decimalPlaces)
          Writes a double precision floating point number (a "double") to the Console with a specified field size and a specified number of decimal places.
 void print(float number)
          Writes a floating point number (a "float") to the Console.
 void print(float number, int fieldSize)
          Writes a floating point number (a "float") to the Console with a specified field size.
 void print(float number, int fieldSize, int decimalPlaces)
          Writes a floating point number (a "double") to the Console with a specified field size and a specified number of decimal places.
 void print(int number)
          Writes the text representation of an 32-bit integer (an "int") to the Console.
 void print(int number, int fieldSize)
          Writes the text representation of an 32-bit integer (an "int") to the Console with a specified field size.
 void print(long number)
          Writes the text representation of an 64-bit integer (a "long") to the Console.
 void print(long number, int fieldSize)
          Writes the text representation of an 64-bit integer (a "long") to the Console with a specified field size.
 void print(short number)
          Writes the text representation of an 16-bit integer (a "short") to the Console.
 void print(short number, int fieldSize)
          Writes the text representation of an 16-bit integer (a "short") to the Console with a specified field size.
abstract  void print(String text)
          Writes a string to the Console.
 void print(String text, int fieldSize)
          Writes a string to the Console with a specified field size..
 void println()
          Writes a newline to the Console.
 void println(boolean value)
          Writes the text representation of a boolean to the Console followed by a newline.
 void println(boolean value, int fieldSize)
          Writes the text representation of a boolean to the Console with a specified field size followed by a newline.
 void println(byte number)
          Writes the text representation of an 8-bit integer (a "byte") to the Console followed by a newline.
 void println(byte number, int fieldSize)
          Writes the text representation of an 8-bit integer (a "byte") to the Console with a specified field size followed by a newline.
 void println(char ch)
          Writes a character to the Console followed by a newline.
 void println(char ch, int fieldSize)
          Writes a character to the Console with a specified field size..
 void println(double number)
          Writes a double precision floating point number (a "double") to the Console followed by a newline.
 void println(double number, int fieldSize)
          Writes a double precision floating point number (a "double") to the Console with a specified field size followed by a newline.
 void println(double number, int fieldSize, int decimalPlaces)
          Writes a double precision floating point number (a "double") to the Console with a specified field size and a specified number of decimal places followed by a newline.
 void println(float number)
          Writes a floating point number (a "float") to the Console followed by a newline.
 void println(float number, int fieldSize)
          Writes a floating point number (a "float") to the Console with a specified field size followed by a newline.
 void println(float number, int fieldSize, int decimalPlaces)
          Writes a floating point number (a "double") to the Console with a specified field size and a specified number of decimal places followed by a newline.
 void println(int number)
          Writes the text representation of an 32-bit integer (an "int") to the Console followed by a newline.
 void println(int number, int fieldSize)
          Writes the text representation of an 32-bit integer (an "int") to the Console with a specified field size followed by a newline.
 void println(long number)
          Writes the text representation of an 64-bit integer (a "long") to the Console followed by a newline.
 void println(long number, int fieldSize)
          Writes the text representation of an 64-bit integer (a "long") to the Console with a specified field size followed by a newline.
 void println(short number)
          Writes the text representation of an 16-bit integer (a "short") to the Console followed by a newline.
 void println(short number, int fieldSize)
          Writes the text representation of an 16-bit integer (a "short") to the Console with a specified field size followed by a newline.
 void println(String text)
          Writes a string to the Console followed by a newline.
 void println(String text, int fieldSize)
          Writes a string to the Console with a specified field size followed by a newline.
protected  void quitProgram()
          Hides the window and quits the program.
 boolean readBoolean()
          Reads a boolean from the Console.
 byte readByte()
          Reads an 8-bit integer (a "byte") from the Console.
abstract  char readChar()
          Reads a single character from the Console.
 double readDouble()
          Reads a double precision floating point number (a "double") from the Console.
 float readFloat()
          Reads a floating point number (a "float") from the Console.
 int readInt()
          Reads a 32-bit integer (an "int") from the Console.
 String readLine()
          Reads a full line of text from the Console.
 long readLong()
          Reads a 64-bit integer (a "long") from the Console.
 short readShort()
          Reads a 16-bit integer (a "short") from the Console.
 String readString()
          Reads a whitespace delimited token from the Console.
protected  String readToken()
          Reads in input from the keyboard buffer until it hits a whitespace, which indicates the end of a token.
protected  void setWindowTitle(String s)
          Sets the window title.
 void windowActivated(WindowEvent e)
          Does nothing.
 void windowClosed(WindowEvent e)
          Does nothing.
 void windowClosing(WindowEvent e)
          Quits the program.
 void windowDeactivated(WindowEvent e)
          Does nothing.
 void windowDeiconified(WindowEvent e)
          Does nothing.
 void windowIconified(WindowEvent e)
          Does nothing.
 void windowOpened(WindowEvent e)
          Does nothing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFFER_SIZE

protected static final int BUFFER_SIZE
See Also:
Constant Field Values

consoleCanvas

ConsoleCanvas consoleCanvas
The drawing surface.


consoleCanvasPanelInner

protected Panel consoleCanvasPanelInner

DEFAULT_COLUMNS

protected static final int DEFAULT_COLUMNS
See Also:
Constant Field Values

DEFAULT_FONT_SIZE

protected static final int DEFAULT_FONT_SIZE
See Also:
Constant Field Values

DEFAULT_ROWS

protected static final int DEFAULT_ROWS
See Also:
Constant Field Values

DEFAULT_TITLE

protected static final String DEFAULT_TITLE
See Also:
Constant Field Values

EMPTY_BUFFER

protected static final int EMPTY_BUFFER
See Also:
Constant Field Values

eofReached

protected boolean eofReached

kbdBuffer

protected char[] kbdBuffer

kbdBufferHead

protected int kbdBufferHead

kbdBufferTail

protected int kbdBufferTail

lineBuffer

protected char[] lineBuffer

lineBufferHead

protected int lineBufferHead

lineBufferTail

protected int lineBufferTail

maxCol

protected int maxCol

maxRow

protected int maxRow

PRINT_COMMAND

protected static final String PRINT_COMMAND
See Also:
Constant Field Values

QUIT_COMMAND

protected static final String QUIT_COMMAND
See Also:
Constant Field Values

SAVE_COMMAND

protected static final String SAVE_COMMAND
See Also:
Constant Field Values

TAB_SIZE

protected static final int TAB_SIZE
See Also:
Constant Field Values

ungotChar

protected int ungotChar

window

protected ConsoleFrame window
Constructor Detail

ConsoleParent

ConsoleParent()
Method Detail

actionPerformed

public void actionPerformed(ActionEvent e)
Quits the program, saves the contents of the window, or prints the contents of the window, depending on which button is pressed. Called by the system when a button in the Console is pressed.

Specified by:
actionPerformed in interface ActionListener

close

public void close()
Closes the console window.


enableButtons

protected void enableButtons(boolean enable)
Enables or disables all the buttons in the Console. Used while the contents of the window is being saved or printed.


focusGained

public void focusGained(FocusEvent e)
Sets the focus to the invisible button and then the console canvas. This is necessary as a work-around to a bug in VisualAge for Java, which gives buttons default focus that can only be removed by making another button a focus. Called by the system when the Console gains focus.

Specified by:
focusGained in interface FocusListener

focusLost

public void focusLost(FocusEvent e)
Does nothing. Called by the system when the Console loses focus.

Specified by:
focusLost in interface FocusListener

initialize

protected void initialize(int rows,
                          int columns,
                          int fontSize,
                          String title)
Initializes the window. Not in the constructor because it needs certain elements that are not ready at construction time.


keyPressed

public void keyPressed(KeyEvent e)
Places a keystroke in the keyboard buffer. It is synchronized so that there can't be a problem with input being taken off the keyboard buffer and placed on the keyboard buffer at the same time.

Specified by:
keyPressed in interface KeyListener

keyReleased

public void keyReleased(KeyEvent e)
Does nothing. Called by the system when a key is released.

Specified by:
keyReleased in interface KeyListener

keyTyped

public void keyTyped(KeyEvent e)
Does nothing. Called by the system when a key is typed.

Specified by:
keyTyped in interface KeyListener

mainStopped

protected void mainStopped()
This method is invoked if the "main" method appears to have stopped executing. This helps the user realize when the program has finished execution.


print

public void print(boolean value)
Writes the text representation of a boolean to the Console.

Parameters:
value - The boolean to be written to the Console.

print

public void print(boolean value,
                  int fieldSize)
Writes the text representation of a boolean to the Console with a specified field size.

Parameters:
value - The boolean to be written to the Console.
fieldSize - The field width that the boolean is to be written in.

print

public void print(byte number)
Writes the text representation of an 8-bit integer (a "byte") to the Console.

Parameters:
number - The number to be written to the Console.

print

public void print(byte number,
                  int fieldSize)
Writes the text representation of an 8-bit integer (a "byte") to the Console with a specified field size.

Parameters:
number - The number to be written to the Console.
fieldSize - The field width that the number is to be written in.

print

public void print(char ch)
Writes a character to the Console.

Parameters:
ch - The character to be written to the Console.

print

public void print(char ch,
                  int fieldSize)
Writes a character to the Console with a specified field size..

Parameters:
ch - The character to be written to the Console.
fieldSize - The field width that the character is to be written in.

print

public void print(double number)
Writes a double precision floating point number (a "double") to the Console.

Parameters:
number - The number to be written to the Console.

print

public void print(double number,
                  int fieldSize)
Writes a double precision floating point number (a "double") to the Console with a specified field size.

Parameters:
number - The number to be written to the Console.
fieldSize - The field width that the number is to be written in.

print

public void print(double number,
                  int fieldSize,
                  int decimalPlaces)
Writes a double precision floating point number (a "double") to the Console with a specified field size and a specified number of decimal places.

Parameters:
number - The number to be written to the Console.
fieldSize - The field width that the number is to be written in.
decimalPlaces - The number of decimal places of the number to be displayed.

print

public void print(float number)
Writes a floating point number (a "float") to the Console.

Parameters:
number - The number to be written to the Console.

print

public void print(float number,
                  int fieldSize)
Writes a floating point number (a "float") to the Console with a specified field size.

Parameters:
number - The number to be written to the Console.
fieldSize - The field width that the number is to be written in.

print

public void print(float number,
                  int fieldSize,
                  int decimalPlaces)
Writes a floating point number (a "double") to the Console with a specified field size and a specified number of decimal places.

Parameters:
number - The number to be written to the Console.
fieldSize - The field width that the number is to be written in.
decimalPlaces - The number of decimal places of the number to be displayed.

print

public void print(int number)
Writes the text representation of an 32-bit integer (an "int") to the Console.

Parameters:
number - The number to be written to the Console.

print

public void print(int number,
                  int fieldSize)
Writes the text representation of an 32-bit integer (an "int") to the Console with a specified field size.

Parameters:
number - The number to be written to the Console.
fieldSize - The field width that the number is to be written in.

print

public void print(long number)
Writes the text representation of an 64-bit integer (a "long") to the Console.

Parameters:
number - The number to be written to the Console.

print

public void print(long number,
                  int fieldSize)
Writes the text representation of an 64-bit integer (a "long") to the Console with a specified field size.

Parameters:
number - The number to be written to the Console.
fieldSize - The field width that the number is to be written in.

print

public void print(short number)
Writes the text representation of an 16-bit integer (a "short") to the Console.

Parameters:
number - The number to be written to the Console.

print

public void print(short number,
                  int fieldSize)
Writes the text representation of an 16-bit integer (a "short") to the Console with a specified field size.

Parameters:
number - The number to be written to the Console.
fieldSize - The field width that the number is to be written in.

print

public abstract void print(String text)
Writes a string to the Console.

Parameters:
text - The string to be written to the Console. This procedure is slightly complicated by the fact that if the line of text went to the end of the line exactly and was followed by a newline, then we only perform one newline.

print

public void print(String text,
                  int fieldSize)
Writes a string to the Console with a specified field size..

Parameters:
text - The string to be written to the Console.
fieldSize - The field width that the string is to be written in.

println

public void println()
Writes a newline to the Console.


println

public void println(boolean value)
Writes the text representation of a boolean to the Console followed by a newline.

Parameters:
value - The boolean to be written to the Console.

println

public void println(boolean value,
                    int fieldSize)
Writes the text representation of a boolean to the Console with a specified field size followed by a newline.

Parameters:
value - The boolean to be written to the Console.
fieldSize - The field width that the boolean is to be written in.

println

public void println(byte number)
Writes the text representation of an 8-bit integer (a "byte") to the Console followed by a newline.

Parameters:
number - The number to be written to the Console.

println

public void println(byte number,
                    int fieldSize)
Writes the text representation of an 8-bit integer (a "byte") to the Console with a specified field size followed by a newline.

Parameters:
number - The number to be written to the Console.
fieldSize - The field width that the number is to be written in.

println

public void println(char ch)
Writes a character to the Console followed by a newline.

Parameters:
ch - The character to be written to the Console.

println

public void println(char ch,
                    int fieldSize)
Writes a character to the Console with a specified field size..

Parameters:
ch - The character to be written to the Console.
fieldSize - The field width that the character is to be written in.

println

public void println(double number)
Writes a double precision floating point number (a "double") to the Console followed by a newline.

Parameters:
number - The number to be written to the Console.

println

public void println(double number,
                    int fieldSize)
Writes a double precision floating point number (a "double") to the Console with a specified field size followed by a newline.

Parameters:
number - The number to be written to the Console.
fieldSize - The field width that the number is to be written in.

println

public void println(double number,
                    int fieldSize,
                    int decimalPlaces)
Writes a double precision floating point number (a "double") to the Console with a specified field size and a specified number of decimal places followed by a newline.

Parameters:
number - The number to be written to the Console.
fieldSize - The field width that the number is to be written in.
decimalPlaces - The number of decimal places of the number to be displayed.

println

public void println(float number)
Writes a floating point number (a "float") to the Console followed by a newline.

Parameters:
number - The number to be written to the Console.

println

public void println(float number,
                    int fieldSize)
Writes a floating point number (a "float") to the Console with a specified field size followed by a newline.

Parameters:
number - The number to be written to the Console.
fieldSize - The field width that the number is to be written in.

println

public void println(float number,
                    int fieldSize,
                    int decimalPlaces)
Writes a floating point number (a "double") to the Console with a specified field size and a specified number of decimal places followed by a newline.

Parameters:
number - The number to be written to the Console.
fieldSize - The field width that the number is to be written in.
decimalPlaces - The number of decimal places of the number to be displayed.

println

public void println(int number)
Writes the text representation of an 32-bit integer (an "int") to the Console followed by a newline.

Parameters:
number - The number to be written to the Console.

println

public void println(int number,
                    int fieldSize)
Writes the text representation of an 32-bit integer (an "int") to the Console with a specified field size followed by a newline.

Parameters:
number - The number to be written to the Console.
fieldSize - The field width that the number is to be written in.

println

public void println(long number)
Writes the text representation of an 64-bit integer (a "long") to the Console followed by a newline.

Parameters:
number - The number to be written to the Console.

println

public void println(long number,
                    int fieldSize)
Writes the text representation of an 64-bit integer (a "long") to the Console with a specified field size followed by a newline.

Parameters:
number - The number to be written to the Console.
fieldSize - The field width that the number is to be written in.

println

public void println(short number)
Writes the text representation of an 16-bit integer (a "short") to the Console followed by a newline.

Parameters:
number - The number to be written to the Console.

println

public void println(short number,
                    int fieldSize)
Writes the text representation of an 16-bit integer (a "short") to the Console with a specified field size followed by a newline.

Parameters:
number - The number to be written to the Console.
fieldSize - The field width that the number is to be written in.

println

public void println(String text)
Writes a string to the Console followed by a newline.

Parameters:
text - The string to be written to the Console.

println

public void println(String text,
                    int fieldSize)
Writes a string to the Console with a specified field size followed by a newline.

Parameters:
text - The string to be written to the Console.
fieldSize - The field width that the string is to be written in.

quitProgram

protected void quitProgram()
Hides the window and quits the program.


readBoolean

public boolean readBoolean()
Reads a boolean from the Console. The actual text in the Console must be either "true" or "false" although case is irrelvant.

Returns:
The boolean value read from the Console.

readByte

public byte readByte()
Reads an 8-bit integer (a "byte") from the Console. The actual text in the Console must be a number from -128 to 127.

Returns:
The byte value read from the Console.

readChar

public abstract char readChar()
Reads a single character from the Console. Note that this discards any whitespace. If you want to get every character on the line, use the readLine () method.

Returns:
The character read from the Console.

readDouble

public double readDouble()
Reads a double precision floating point number (a "double") from the Console.

Returns:
The double value read from the Console.

readFloat

public float readFloat()
Reads a floating point number (a "float") from the Console.

Returns:
The float value read from the Console.

readInt

public int readInt()
Reads a 32-bit integer (an "int") from the Console. The actual text in the Console must be a number from -2147483648 to 2147483647.

Returns:
The int value read from the Console.

readLine

public String readLine()
Reads a full line of text from the Console.

Returns:
The line of text read from the Console.

readLong

public long readLong()
Reads a 64-bit integer (a "long") from the Console.

Returns:
The long value read from the Console.

readShort

public short readShort()
Reads a 16-bit integer (a "short") from the Console. The actual text in the Console must be a number from -32768 to 32767.

Returns:
The short value read from the Console.

readString

public String readString()
Reads a whitespace delimited token from the Console.

Returns:
The token read from the Console.

readToken

protected String readToken()
Reads in input from the keyboard buffer until it hits a whitespace, which indicates the end of a token.


setWindowTitle

protected void setWindowTitle(String s)
Sets the window title.

Parameters:
e - The window event

windowActivated

public void windowActivated(WindowEvent e)
Does nothing. Called by the system after the window has been activated.

Specified by:
windowActivated in interface WindowListener
Parameters:
e - The window event

windowClosed

public void windowClosed(WindowEvent e)
Does nothing. Called by the system after the window has been closed (dispose () has been called).

Specified by:
windowClosed in interface WindowListener
Parameters:
e - The window event

windowClosing

public void windowClosing(WindowEvent e)
Quits the program. Called by the system when the close box of the window has been clicked.

Specified by:
windowClosing in interface WindowListener
Parameters:
e - The window event

windowDeactivated

public void windowDeactivated(WindowEvent e)
Does nothing. Called by the system after the window has been deactivated.

Specified by:
windowDeactivated in interface WindowListener
Parameters:
e - The window event

windowDeiconified

public void windowDeiconified(WindowEvent e)
Does nothing. Called by the system after the window has been deminimized.

Specified by:
windowDeiconified in interface WindowListener
Parameters:
e - The window event

windowIconified

public void windowIconified(WindowEvent e)
Does nothing. Called by the system after the window has been minimized.

Specified by:
windowIconified in interface WindowListener
Parameters:
e - The window event

windowOpened

public void windowOpened(WindowEvent e)
Does nothing. Called by the system after the window has been opened for the first time.

Specified by:
windowOpened in interface WindowListener
Parameters:
e - The window event