Class Console

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

public class Console
extends ConsoleParent


Field Summary
protected  int actualCol
           
protected  int actualRow
           
protected  boolean clearToEOL
           
protected  int currentCol
          Console text variables
protected  int currentRow
          Console text variables
protected  boolean echoOn
           
protected  Font font
           
protected  ConsoleCanvasGraphics graphicsCanvas
           
protected  Color graphicsColor
          Console graphics variables
protected static boolean mainReturned
           
protected  int startCol
           
protected  int startRow
           
protected  Color textBGColor
           
protected  Color textColor
           
 
Fields inherited from class ConsoleParent
BUFFER_SIZE, consoleCanvas, consoleCanvasPanelInner, DEFAULT_COLUMNS, DEFAULT_FONT_SIZE, DEFAULT_ROWS, DEFAULT_TITLE, EMPTY_BUFFER, eofReached, kbdBuffer, kbdBufferHead, kbdBufferTail, lineBuffer, lineBufferHead, lineBufferTail, maxCol, maxRow, PRINT_COMMAND, QUIT_COMMAND, SAVE_COMMAND, TAB_SIZE, ungotChar, window
 
Constructor Summary
Console()
          Creates a console using the default values of: 25x80 screen, 14 pt font, "Console" as title.
Console(int fontSize)
          Creates a console using the default values of: 25x80 screen, "Console" as title.
Console(int rows, int columns)
          Creates a console using the default values of: 14 pt font, "Console" as title.
Console(int rows, int columns, int fontSize)
          Creates a console using the default values of: "Console" as title.
Console(int rows, int columns, int fontSize, String title)
          Creates a console.
Console(int rows, int columns, String title)
          Creates a console using the default values of: 14 pt font.
Console(int fontSize, String title)
          Creates a console using the default values of: 25x80 screen.
Console(String title)
          Creates a console using the default values of: 25x80 screen, 14 pt font.
 
Method Summary
 void clear()
          Clears the screen and moves the cursor to the top left corner.
 void clearRect(int x, int y, int width, int height)
          Clears a rectangle in the console to white.
 void copyArea(int x, int y, int width, int height, int delta_x, int delta_y)
          Copies an area of the screen from (x, y) to (x + width, y + height) onto the screen with top corner at (x + delta_x, y + delta_y).
 void draw3DRect(int x, int y, int width, int height, boolean raised)
          Draws a 3D rectangle on the screen from (x, y) to (x + width, y + width).
 void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
          Draws an arc on the screen from (x, y) to (x + width, y + height) from startAngle to startAngle + arcAngle in specified colour.
 void drawImage(Image img, int x, int y, ImageObserver obs)
          Draws an image on the screen at (x, y).
 void drawLine(int x1, int y1, int x2, int y2)
          Draws a line on the screen from (x1, y1) to (x2, y2).
 void drawMapleLeaf(int x, int y, int width, int height)
          Draws a maple leaf on the screen from (x, y) to (x + width, y + width).
 void drawOval(int x, int y, int width, int height)
          Draws an oval on the screen in the sqaure from (x, y) to (x + width, y + height).
 void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
          Draws a polygon specified by the arrays of points.
 void drawRect(int x, int y, int width, int height)
          Draws a rectangle on the screen from (x, y) to (x + width, y + width).
 void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Draws a rounded rectangle on the screen from (x, y) to (x + width, y + width).
 void drawStar(int x, int y, int width, int height)
          Draws a star on the screen from (x, y) to (x + width, y + width).
 void drawString(String str, int x, int y)
          Draws a text on the screen at location (x, y).
protected  void eraseLineOfInput()
          Erases the entire line of input.
protected  void erasePreviousChar()
          Erases the previous character in a line of input.
 void fill3DRect(int x, int y, int width, int height, boolean raised)
          Draws a filled 3D rectangle on the screen from (x, y) to (x + width, y + width).
 void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
          Draws a filled arc on the screen from (x, y) to (x + width, y + height) from startAngle to startAngle + arcAngle in specified colour.
 void fillMapleLeaf(int x, int y, int width, int height)
          Draws a filled maple leaf on the screen from (x, y) to (x + width, y + width).
 void fillOval(int x, int y, int width, int height)
          Draws a filled oval on the screen in the sqaure from (x, y) to (x + width, y + height).
 void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
          Draws a filled polygon specified by the arrays of points..
 void fillRect(int x, int y, int width, int height)
          Draws a filled rectangle on the screen from (x, y) to (x + width, y + width).
 void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Draws a filled rounded rectangle on the screen from (x, y) to (x + width, y + width).
 void fillStar(int x, int y, int width, int height)
          Draws a filled star on the screen from (x, y) to (x + width, y + width).
 char getChar()
          Returns the next character entered on the keyboard.
 int getColumn()
          Returns the current column number of the cursor.
 int getHeight()
          Returns the height of the console drawing surface in pixels.
 int getMaxColumns()
          Returns the number of columns in the console window.
 int getMaxRows()
          Returns the number of rows in the console window.
 int getRow()
          Returns the current row number of the cursor.
 int getWidth()
          Returns the width of the console drawing surface in pixels.
 boolean isCharAvail()
          Returns whether a character is available in the keyboard buffer.
static void mainReturned()
           
 int maxcol()
          Returns the number of columns in the console window.
 int maxrow()
          Returns the number of rows in the console window.
 int maxx()
          Returns the maximum x coordinate of the console window in pixels.
 int maxy()
          Returns the maximum y coordinate of the console window in pixels.
 void print(String text)
          Write a string to the Console.
 char readChar()
          Reads a single character from the Console.
 void setColor(Color color)
          Sets the foreground color for any graphics.
 void setColour(Color colour)
          Sets the foreground colour for any graphics.
 void setCursor(int row, int column)
          Moves the cursor to the specified row and column.
 void setCursorVisible(boolean visible)
          Makes the blinking cursor visible or invisible.
 void setFont(Font font)
          Sets the font for the drawString method.
 void setPaintMode()
          Sets the drawing mode for any graphics to "Paint".
 void setTextBackgroundColor(Color color)
          Sets the background color for any text.
 void setTextBackgroundColour(Color colour)
          Sets the background color for any text.
 void setTextColor(Color color)
          Sets the foreground color for any text.
 void setTextColour(Color colour)
          Sets the foreground colour for any text.
 void setXORMode(Color xorColor)
          Sets the drawing mode for any graphics to "XOR".
 
Methods inherited from class ConsoleParent
actionPerformed, close, enableButtons, focusGained, focusLost, initialize, keyPressed, keyReleased, keyTyped, mainStopped, print, print, print, print, print, print, print, print, print, print, print, print, print, print, print, print, print, print, print, println, println, println, println, println, println, println, println, println, println, println, println, println, println, println, println, println, println, println, println, println, quitProgram, readBoolean, readByte, readDouble, readFloat, readInt, readLine, readLong, readShort, readString, readToken, setWindowTitle, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpened
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

actualCol

protected int actualCol

actualRow

protected int actualRow

clearToEOL

protected boolean clearToEOL

currentCol

protected int currentCol
Console text variables


currentRow

protected int currentRow
Console text variables


echoOn

protected boolean echoOn

font

protected Font font

graphicsCanvas

protected ConsoleCanvasGraphics graphicsCanvas

graphicsColor

protected Color graphicsColor
Console graphics variables


mainReturned

protected static boolean mainReturned

startCol

protected int startCol

startRow

protected int startRow

textBGColor

protected Color textBGColor

textColor

protected Color textColor
Constructor Detail

Console

public Console()
Creates a console using the default values of: 25x80 screen, 14 pt font, "Console" as title.


Console

public Console(int fontSize)
Creates a console using the default values of: 25x80 screen, "Console" as title.

Parameters:
fontSize - The size of the font to be used in the Console window

Console

public Console(int rows,
               int columns)
Creates a console using the default values of: 14 pt font, "Console" as title.

Parameters:
rows - The height of the window in rows
columns - The width of the window in columns

Console

public Console(int rows,
               int columns,
               int fontSize)
Creates a console using the default values of: "Console" as title.

Parameters:
rows - The height of the window in rows
columns - The width of the window in columns
fontSize - The size of the font to be used in the Console window

Console

public Console(int rows,
               int columns,
               int fontSize,
               String title)
Creates a console.

Parameters:
rows - The height of the window in rows
columns - The width of the window in columns
fontSize - The size of the font to be used in the Console window
title - The title of the Console window

Console

public Console(int rows,
               int columns,
               String title)
Creates a console using the default values of: 14 pt font.

Parameters:
rows - The height of the window in rows
columns - The width of the window in columns
title - The title of the Console window

Console

public Console(int fontSize,
               String title)
Creates a console using the default values of: 25x80 screen.

Parameters:
fontSize - The size of the font to be used in the Console window.
title - The title of the Console window.

Console

public Console(String title)
Creates a console using the default values of: 25x80 screen, 14 pt font.

Parameters:
title - The title of the Console window
Method Detail

clear

public void clear()
Clears the screen and moves the cursor to the top left corner.


clearRect

public void clearRect(int x,
                      int y,
                      int width,
                      int height)
Clears a rectangle in the console to white.

See Also:
Graphics.clearRect

copyArea

public void copyArea(int x,
                     int y,
                     int width,
                     int height,
                     int delta_x,
                     int delta_y)
Copies an area of the screen from (x, y) to (x + width, y + height) onto the screen with top corner at (x + delta_x, y + delta_y).

See Also:
Graphics.copyArea

draw3DRect

public void draw3DRect(int x,
                       int y,
                       int width,
                       int height,
                       boolean raised)
Draws a 3D rectangle on the screen from (x, y) to (x + width, y + width).

See Also:
Graphics.draw3DRect

drawArc

public void drawArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)
Draws an arc on the screen from (x, y) to (x + width, y + height) from startAngle to startAngle + arcAngle in specified colour.

See Also:
Graphics.drawArc

drawImage

public void drawImage(Image img,
                      int x,
                      int y,
                      ImageObserver obs)
Draws an image on the screen at (x, y).

See Also:
Graphics.drawImage

drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2)
Draws a line on the screen from (x1, y1) to (x2, y2).

See Also:
Graphics.drawLine

drawMapleLeaf

public void drawMapleLeaf(int x,
                          int y,
                          int width,
                          int height)
Draws a maple leaf on the screen from (x, y) to (x + width, y + width).

Parameters:
x - The x coordinate of the top left corner of the rectangle that the maple leaf is inscribed in.
y - The y coordinate of the top left corner of the rectangle that the maple leaf is inscribed in.
width - The width of the rectangle that the maple leaf is inscribed in.
height - The height of the rectangle that the maple leaf is inscribed in.

drawOval

public void drawOval(int x,
                     int y,
                     int width,
                     int height)
Draws an oval on the screen in the sqaure from (x, y) to (x + width, y + height).

See Also:
Graphics.drawOval

drawPolygon

public void drawPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints)
Draws a polygon specified by the arrays of points.

See Also:
Graphics.drawPolygon

drawRect

public void drawRect(int x,
                     int y,
                     int width,
                     int height)
Draws a rectangle on the screen from (x, y) to (x + width, y + width).

See Also:
Graphics.drawRect

drawRoundRect

public void drawRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Draws a rounded rectangle on the screen from (x, y) to (x + width, y + width).

See Also:
Graphics.drawRoundRect

drawStar

public void drawStar(int x,
                     int y,
                     int width,
                     int height)
Draws a star on the screen from (x, y) to (x + width, y + width).

Parameters:
x - The x coordinate of the top left corner of the rectangle that the star is inscribed in.
y - The y coordinate of the top left corner of the rectangle that the star is inscribed in.
width - The width of the rectangle that the star is inscribed in.
height - The height of the rectangle that the star is inscribed in.

drawString

public void drawString(String str,
                       int x,
                       int y)
Draws a text on the screen at location (x, y).

See Also:
Graphics.drawString

eraseLineOfInput

protected void eraseLineOfInput()
Erases the entire line of input. Called when the user presses Ctrl+U when typing.


erasePreviousChar

protected void erasePreviousChar()
Erases the previous character in a line of input. Called when the user presses backspace when typing.


fill3DRect

public void fill3DRect(int x,
                       int y,
                       int width,
                       int height,
                       boolean raised)
Draws a filled 3D rectangle on the screen from (x, y) to (x + width, y + width).

See Also:
Graphics.fill3DRect

fillArc

public void fillArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)
Draws a filled arc on the screen from (x, y) to (x + width, y + height) from startAngle to startAngle + arcAngle in specified colour.

See Also:
Graphics.fillArc

fillMapleLeaf

public void fillMapleLeaf(int x,
                          int y,
                          int width,
                          int height)
Draws a filled maple leaf on the screen from (x, y) to (x + width, y + width).

Parameters:
x - int The x coordinate of the top left corner of the rectangle that the maple leaf is inscribed in.
y - int The y coordinate of the top left corner of the rectangle that the maple leaf is inscribed in.
width - int The width of the rectangle that the maple leaf is inscribed in.
height - int The height of the rectangle that the maple leaf is inscribed in.

fillOval

public void fillOval(int x,
                     int y,
                     int width,
                     int height)
Draws a filled oval on the screen in the sqaure from (x, y) to (x + width, y + height).

See Also:
Graphics.fillOval

fillPolygon

public void fillPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints)
Draws a filled polygon specified by the arrays of points..

See Also:
Graphics.fillPolygon

fillRect

public void fillRect(int x,
                     int y,
                     int width,
                     int height)
Draws a filled rectangle on the screen from (x, y) to (x + width, y + width).

See Also:
Graphics.fillRect

fillRoundRect

public void fillRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Draws a filled rounded rectangle on the screen from (x, y) to (x + width, y + width).

See Also:
Graphics.fillRoundRect

fillStar

public void fillStar(int x,
                     int y,
                     int width,
                     int height)
Draws a filled star on the screen from (x, y) to (x + width, y + width).

Parameters:
x - The x coordinate of the top left corner of the rectangle that the star is inscribed in.
y - The y coordinate of the top left corner of the rectangle that the star is inscribed in.
width - The width of the rectangle that the star is inscribed in.
height - The height of the rectangle that the star is inscribed in.

getChar

public char getChar()
Returns the next character entered on the keyboard. Ignores characters currently in the line buffer.

Returns:
The next character entered on the keyboard.

getColumn

public int getColumn()
Returns the current column number of the cursor.

Returns:
The current column number of the cursor.

getHeight

public int getHeight()
Returns the height of the console drawing surface in pixels.

Returns:
The height of the console window in pixels.

getMaxColumns

public int getMaxColumns()
Returns the number of columns in the console window.

Returns:
The width of the screen in columns.

getMaxRows

public int getMaxRows()
Returns the number of rows in the console window.

Returns:
The height of the screen in rows.

getRow

public int getRow()
Returns the current row number of the cursor.

Returns:
The current row number of the cursor.

getWidth

public int getWidth()
Returns the width of the console drawing surface in pixels.

Returns:
The width of the console drawing surface in pixels.

isCharAvail

public boolean isCharAvail()
Returns whether a character is available in the keyboard buffer. Ignores characters currently in the line buffer.

Returns:
true if a character is ready to be read with getChar

mainReturned

public static void mainReturned()

maxcol

public int maxcol()
Returns the number of columns in the console window.

Returns:
The width of the screen in columns.

maxrow

public int maxrow()
Returns the number of rows in the console window.

Returns:
The height of the screen in rows.

maxx

public int maxx()
Returns the maximum x coordinate of the console window in pixels. Available for compatibility with first printing of "Programming Concepts"

Returns:
The maximum x coordinate of the console window in pixels.

maxy

public int maxy()
Returns the maximum y coordinate of the console window in pixels. Available for compatibility with first printing of "Programming Concepts"

Returns:
The maximum y coordinate the console window in pixels.

print

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

Specified by:
print in class ConsoleParent
Parameters:
text - The string to be written to the Console

readChar

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

Specified by:
readChar in class ConsoleParent
Returns:
The character read from the Console

setColor

public void setColor(Color color)
Sets the foreground color for any graphics.

See Also:
Graphics.setColor

setColour

public void setColour(Color colour)
Sets the foreground colour for any graphics.

See Also:
Graphics.setColor

setCursor

public void setCursor(int row,
                      int column)
Moves the cursor to the specified row and column.

Parameters:
row - The row to move the cursor to
column - The column to move the cursor to

setCursorVisible

public void setCursorVisible(boolean visible)
Makes the blinking cursor visible or invisible.


setFont

public void setFont(Font font)
Sets the font for the drawString method.

See Also:
Graphics.setFont

setPaintMode

public void setPaintMode()
Sets the drawing mode for any graphics to "Paint".

See Also:
Graphics.setPaintMode

setTextBackgroundColor

public void setTextBackgroundColor(Color color)
Sets the background color for any text.

Parameters:
color - The color that text displayed by print and println methods will appear on.

setTextBackgroundColour

public void setTextBackgroundColour(Color colour)
Sets the background color for any text.

Parameters:
colour - The color that text displayed by print and println methods will appear on.

setTextColor

public void setTextColor(Color color)
Sets the foreground color for any text.

Parameters:
color - The color that text displayed by print and println methods will appear in.

setTextColour

public void setTextColour(Color colour)
Sets the foreground colour for any text.

Parameters:
colour - The color that text displayed by print and println methods will appear in.

setXORMode

public void setXORMode(Color xorColor)
Sets the drawing mode for any graphics to "XOR".

See Also:
Graphics.setXORMode