Package hsa
Class Console
- java.lang.Object
-
- hsa.Console
-
- All Implemented Interfaces:
java.awt.event.ActionListener,java.awt.event.FocusListener,java.awt.event.KeyListener,java.awt.event.WindowListener,java.util.EventListener
public class Console extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected intactualColprotected intactualRowprotected static intBUFFER_SIZEprotected booleanclearToEOLprotected java.awt.PanelconsoleCanvasPanelInnerprotected intcurrentColConsole text variablesprotected intcurrentRowConsole text variablesprotected static intDEFAULT_COLUMNSprotected static intDEFAULT_FONT_SIZEprotected static intDEFAULT_ROWSprotected static java.lang.StringDEFAULT_TITLEprotected booleanechoOnprotected static intEMPTY_BUFFERprotected booleaneofReachedprotected java.awt.Fontfontprotected hsa.ConsoleCanvasGraphicsgraphicsCanvasprotected java.awt.ColorgraphicsColorConsole graphics variablesprotected char[]kbdBufferprotected intkbdBufferHeadprotected intkbdBufferTailprotected char[]lineBufferprotected intlineBufferHeadprotected intlineBufferTailprotected static booleanmainReturnedprotected intmaxColprotected intmaxRowprotected static java.lang.StringPRINT_COMMANDprotected static java.lang.StringQUIT_COMMANDprotected static java.lang.StringSAVE_COMMANDprotected intstartColprotected intstartRowprotected static intTAB_SIZEprotected java.awt.ColortextBGColorprotected java.awt.ColortextColorprotected intungotCharprotected hsa.ConsoleFramewindow
-
Constructor Summary
Constructors Constructor Description 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, java.lang.String title)Creates a console.Console(int rows, int columns, java.lang.String title)Creates a console using the default values of: 14 pt font.Console(int fontSize, java.lang.String title)Creates a console using the default values of: 25x80 screen.Console(java.lang.String title)Creates a console using the default values of: 25x80 screen, 14 pt font.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactionPerformed(java.awt.event.ActionEvent e)Quits the program, saves the contents of the window, or prints the contents of the window, depending on which button is pressed.voidclear()Clears the screen and moves the cursor to the top left corner.voidclearRect(int x, int y, int width, int height)Clears a rectangle in the console to white.voidclose()Closes the console window.voidcopyArea(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).voiddraw3DRect(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).voiddrawArc(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.voiddrawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver obs)Draws an image on the screen at (x, y).voiddrawLine(int x1, int y1, int x2, int y2)Draws a line on the screen from (x1, y1) to (x2, y2).voiddrawMapleLeaf(int x, int y, int width, int height)Draws a maple leaf on the screen from (x, y) to (x + width, y + width).voiddrawOval(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).voiddrawPolygon(int[] xPoints, int[] yPoints, int nPoints)Draws a polygon specified by the arrays of points.voiddrawRect(int x, int y, int width, int height)Draws a rectangle on the screen from (x, y) to (x + width, y + width).voiddrawRoundRect(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).voiddrawStar(int x, int y, int width, int height)Draws a star on the screen from (x, y) to (x + width, y + width).voiddrawString(java.lang.String str, int x, int y)Draws a text on the screen at location (x, y).protected voidenableButtons(boolean enable)Enables or disables all the buttons in the Console.protected voideraseLineOfInput()Erases the entire line of input.protected voiderasePreviousChar()Erases the previous character in a line of input.voidfill3DRect(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).voidfillArc(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.voidfillMapleLeaf(int x, int y, int width, int height)Draws a filled maple leaf on the screen from (x, y) to (x + width, y + width).voidfillOval(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).voidfillPolygon(int[] xPoints, int[] yPoints, int nPoints)Draws a filled polygon specified by the arrays of points..voidfillRect(int x, int y, int width, int height)Draws a filled rectangle on the screen from (x, y) to (x + width, y + width).voidfillRoundRect(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).voidfillStar(int x, int y, int width, int height)Draws a filled star on the screen from (x, y) to (x + width, y + width).voidfocusGained(java.awt.event.FocusEvent e)Sets the focus to the invisible button and then the console canvas.voidfocusLost(java.awt.event.FocusEvent e)Does nothing.chargetChar()Returns the next character entered on the keyboard.intgetColumn()Returns the current column number of the cursor.intgetHeight()Returns the height of the console drawing surface in pixels.intgetMaxColumns()Returns the number of columns in the console window.intgetMaxRows()Returns the number of rows in the console window.intgetRow()Returns the current row number of the cursor.intgetWidth()Returns the width of the console drawing surface in pixels.protected voidinitialize(int rows, int columns, int fontSize, java.lang.String title)Initializes the window.booleanisCharAvail()Returns whether a character is available in the keyboard buffer.voidkeyPressed(java.awt.event.KeyEvent e)Places a keystroke in the keyboard buffer.voidkeyReleased(java.awt.event.KeyEvent e)Does nothing.voidkeyTyped(java.awt.event.KeyEvent e)Does nothing.static voidmainReturned()protected voidmainStopped()This method is invoked if the "main" method appears to have stopped executing.intmaxcol()Returns the number of columns in the console window.intmaxrow()Returns the number of rows in the console window.intmaxx()Returns the maximum x coordinate of the console window in pixels.intmaxy()Returns the maximum y coordinate of the console window in pixels.voidprint(boolean value)Writes the text representation of a boolean to the Console.voidprint(boolean value, int fieldSize)Writes the text representation of a boolean to the Console with a specified field size.voidprint(byte number)Writes the text representation of an 8-bit integer (a "byte") to the Console.voidprint(byte number, int fieldSize)Writes the text representation of an 8-bit integer (a "byte") to the Console with a specified field size.voidprint(char ch)Writes a character to the Console.voidprint(char ch, int fieldSize)Writes a character to the Console with a specified field size..voidprint(double number)Writes a double precision floating point number (a "double") to the Console.voidprint(double number, int fieldSize)Writes a double precision floating point number (a "double") to the Console with a specified field size.voidprint(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.voidprint(float number)Writes a floating point number (a "float") to the Console.voidprint(float number, int fieldSize)Writes a floating point number (a "float") to the Console with a specified field size.voidprint(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.voidprint(int number)Writes the text representation of an 32-bit integer (an "int") to the Console.voidprint(int number, int fieldSize)Writes the text representation of an 32-bit integer (an "int") to the Console with a specified field size.voidprint(long number)Writes the text representation of an 64-bit integer (a "long") to the Console.voidprint(long number, int fieldSize)Writes the text representation of an 64-bit integer (a "long") to the Console with a specified field size.voidprint(short number)Writes the text representation of an 16-bit integer (a "short") to the Console.voidprint(short number, int fieldSize)Writes the text representation of an 16-bit integer (a "short") to the Console with a specified field size.voidprint(java.lang.String text)Write a string to the Console.voidprint(java.lang.String text, int fieldSize)Writes a string to the Console with a specified field size..voidprintln()Writes a newline to the Console.voidprintln(boolean value)Writes the text representation of a boolean to the Console followed by a newline.voidprintln(boolean value, int fieldSize)Writes the text representation of a boolean to the Console with a specified field size followed by a newline.voidprintln(byte number)Writes the text representation of an 8-bit integer (a "byte") to the Console followed by a newline.voidprintln(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.voidprintln(char ch)Writes a character to the Console followed by a newline.voidprintln(char ch, int fieldSize)Writes a character to the Console with a specified field size..voidprintln(double number)Writes a double precision floating point number (a "double") to the Console followed by a newline.voidprintln(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.voidprintln(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.voidprintln(float number)Writes a floating point number (a "float") to the Console followed by a newline.voidprintln(float number, int fieldSize)Writes a floating point number (a "float") to the Console with a specified field size followed by a newline.voidprintln(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.voidprintln(int number)Writes the text representation of an 32-bit integer (an "int") to the Console followed by a newline.voidprintln(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.voidprintln(long number)Writes the text representation of an 64-bit integer (a "long") to the Console followed by a newline.voidprintln(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.voidprintln(short number)Writes the text representation of an 16-bit integer (a "short") to the Console followed by a newline.voidprintln(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.voidprintln(java.lang.String text)Writes a string to the Console followed by a newline.voidprintln(java.lang.String text, int fieldSize)Writes a string to the Console with a specified field size followed by a newline.protected voidquitProgram()Hides the window and quits the program.booleanreadBoolean()Reads a boolean from the Console.bytereadByte()Reads an 8-bit integer (a "byte") from the Console.charreadChar()Reads a single character from the Console.doublereadDouble()Reads a double precision floating point number (a "double") from the Console.floatreadFloat()Reads a floating point number (a "float") from the Console.intreadInt()Reads a 32-bit integer (an "int") from the Console.java.lang.StringreadLine()Reads a full line of text from the Console.longreadLong()Reads a 64-bit integer (a "long") from the Console.shortreadShort()Reads a 16-bit integer (a "short") from the Console.java.lang.StringreadString()Reads a whitespace delimited token from the Console.protected java.lang.StringreadToken()Reads in input from the keyboard buffer until it hits a whitespace, which indicates the end of a token.voidsetColor(java.awt.Color color)Sets the foreground color for any graphics.voidsetColour(java.awt.Color colour)Sets the foreground colour for any graphics.voidsetCursor(int row, int column)Moves the cursor to the specified row and column.voidsetCursorVisible(boolean visible)Makes the blinking cursor visible or invisible.voidsetFont(java.awt.Font font)Sets the font for the drawString method.voidsetPaintMode()Sets the drawing mode for any graphics to "Paint".voidsetTextBackgroundColor(java.awt.Color color)Sets the background color for any text.voidsetTextBackgroundColour(java.awt.Color colour)Sets the background color for any text.voidsetTextColor(java.awt.Color color)Sets the foreground color for any text.voidsetTextColour(java.awt.Color colour)Sets the foreground colour for any text.protected voidsetWindowTitle(java.lang.String s)Sets the window title.voidsetXORMode(java.awt.Color xorColor)Sets the drawing mode for any graphics to "XOR".voidwindowActivated(java.awt.event.WindowEvent e)Does nothing.voidwindowClosed(java.awt.event.WindowEvent e)Does nothing.voidwindowClosing(java.awt.event.WindowEvent e)Quits the program.voidwindowDeactivated(java.awt.event.WindowEvent e)Does nothing.voidwindowDeiconified(java.awt.event.WindowEvent e)Does nothing.voidwindowIconified(java.awt.event.WindowEvent e)Does nothing.voidwindowOpened(java.awt.event.WindowEvent e)Does nothing.
-
-
-
Field Detail
-
currentRow
protected int currentRow
Console text variables
-
currentCol
protected int currentCol
Console text variables
-
actualRow
protected int actualRow
-
actualCol
protected int actualCol
-
startCol
protected int startCol
-
startRow
protected int startRow
-
textColor
protected java.awt.Color textColor
-
textBGColor
protected java.awt.Color textBGColor
-
echoOn
protected boolean echoOn
-
clearToEOL
protected boolean clearToEOL
-
graphicsColor
protected java.awt.Color graphicsColor
Console graphics variables
-
font
protected java.awt.Font font
-
graphicsCanvas
protected hsa.ConsoleCanvasGraphics graphicsCanvas
-
mainReturned
protected static boolean mainReturned
-
SAVE_COMMAND
protected static final java.lang.String SAVE_COMMAND
- See Also:
- Constant Field Values
-
PRINT_COMMAND
protected static final java.lang.String PRINT_COMMAND
- See Also:
- Constant Field Values
-
QUIT_COMMAND
protected static final java.lang.String QUIT_COMMAND
- See Also:
- Constant Field Values
-
DEFAULT_ROWS
protected static final int DEFAULT_ROWS
- See Also:
- Constant Field Values
-
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_TITLE
protected static final java.lang.String DEFAULT_TITLE
- See Also:
- Constant Field Values
-
TAB_SIZE
protected static final int TAB_SIZE
- See Also:
- Constant Field Values
-
window
protected hsa.ConsoleFrame window
-
maxRow
protected int maxRow
-
maxCol
protected int maxCol
-
BUFFER_SIZE
protected static final int BUFFER_SIZE
- See Also:
- Constant Field Values
-
EMPTY_BUFFER
protected static final int EMPTY_BUFFER
- See Also:
- Constant Field Values
-
kbdBuffer
protected char[] kbdBuffer
-
kbdBufferHead
protected int kbdBufferHead
-
kbdBufferTail
protected int kbdBufferTail
-
lineBuffer
protected char[] lineBuffer
-
lineBufferHead
protected int lineBufferHead
-
lineBufferTail
protected int lineBufferTail
-
ungotChar
protected int ungotChar
-
consoleCanvasPanelInner
protected java.awt.Panel consoleCanvasPanelInner
-
eofReached
protected boolean eofReached
-
-
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 rowscolumns- 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 rowscolumns- The width of the window in columnsfontSize- The size of the font to be used in the Console window
-
Console
public Console(int rows, int columns, int fontSize, java.lang.String title)Creates a console.- Parameters:
rows- The height of the window in rowscolumns- The width of the window in columnsfontSize- The size of the font to be used in the Console windowtitle- The title of the Console window
-
Console
public Console(int rows, int columns, java.lang.String title)Creates a console using the default values of: 14 pt font.- Parameters:
rows- The height of the window in rowscolumns- The width of the window in columnstitle- The title of the Console window
-
Console
public Console(int fontSize, java.lang.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(java.lang.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:
java.awt.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:
java.awt.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:
java.awt.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:
java.awt.Graphics.drawArc
-
drawImage
public void drawImage(java.awt.Image img, int x, int y, java.awt.image.ImageObserver obs)Draws an image on the screen at (x, y).- See Also:
java.awt.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:
java.awt.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:
java.awt.Graphics.drawOval
-
drawPolygon
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)Draws a polygon specified by the arrays of points.- See Also:
java.awt.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:
java.awt.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:
java.awt.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(java.lang.String str, int x, int y)Draws a text on the screen at location (x, y).- See Also:
java.awt.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:
java.awt.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:
java.awt.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:
java.awt.Graphics.fillOval
-
fillPolygon
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)Draws a filled polygon specified by the arrays of points..- See Also:
java.awt.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:
java.awt.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:
java.awt.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.
-
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
-
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.
-
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(java.lang.String text)
Write a string to the Console.- 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.- Returns:
- The character read from the Console
-
setColor
public void setColor(java.awt.Color color)
Sets the foreground color for any graphics.- See Also:
java.awt.Graphics.setColor
-
setColour
public void setColour(java.awt.Color colour)
Sets the foreground colour for any graphics.- See Also:
java.awt.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 tocolumn- The column to move the cursor to
-
setCursorVisible
public void setCursorVisible(boolean visible)
Makes the blinking cursor visible or invisible.
-
setFont
public void setFont(java.awt.Font font)
Sets the font for the drawString method.- See Also:
java.awt.Graphics.setFont
-
setPaintMode
public void setPaintMode()
Sets the drawing mode for any graphics to "Paint".- See Also:
java.awt.Graphics.setPaintMode
-
setTextBackgroundColor
public void setTextBackgroundColor(java.awt.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(java.awt.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(java.awt.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(java.awt.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(java.awt.Color xorColor)
Sets the drawing mode for any graphics to "XOR".- See Also:
java.awt.Graphics.setXORMode
-
mainReturned
public static void mainReturned()
-
initialize
protected void initialize(int rows, int columns, int fontSize, java.lang.String title)Initializes the window. Not in the constructor because it needs certain elements that are not ready at construction time.
-
actionPerformed
public void actionPerformed(java.awt.event.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:
actionPerformedin interfacejava.awt.event.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(java.awt.event.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:
focusGainedin interfacejava.awt.event.FocusListener
-
focusLost
public void focusLost(java.awt.event.FocusEvent e)
Does nothing. Called by the system when the Console loses focus.- Specified by:
focusLostin interfacejava.awt.event.FocusListener
-
keyPressed
public void keyPressed(java.awt.event.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:
keyPressedin interfacejava.awt.event.KeyListener
-
keyReleased
public void keyReleased(java.awt.event.KeyEvent e)
Does nothing. Called by the system when a key is released.- Specified by:
keyReleasedin interfacejava.awt.event.KeyListener
-
keyTyped
public void keyTyped(java.awt.event.KeyEvent e)
Does nothing. Called by the system when a key is typed.- Specified by:
keyTypedin interfacejava.awt.event.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(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(java.lang.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.
-
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 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.
-
println
public void println()
Writes a newline to the Console.
-
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(java.lang.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(java.lang.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.
-
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(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.
-
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.
-
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 java.lang.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 java.lang.String readString()
Reads a whitespace delimited token from the Console.- Returns:
- The token read from the Console.
-
readToken
protected java.lang.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(java.lang.String s)
Sets the window title.- Parameters:
e- The window event
-
windowActivated
public void windowActivated(java.awt.event.WindowEvent e)
Does nothing. Called by the system after the window has been activated.- Specified by:
windowActivatedin interfacejava.awt.event.WindowListener- Parameters:
e- The window event
-
windowClosed
public void windowClosed(java.awt.event.WindowEvent e)
Does nothing. Called by the system after the window has been closed (dispose () has been called).- Specified by:
windowClosedin interfacejava.awt.event.WindowListener- Parameters:
e- The window event
-
windowClosing
public void windowClosing(java.awt.event.WindowEvent e)
Quits the program. Called by the system when the close box of the window has been clicked.- Specified by:
windowClosingin interfacejava.awt.event.WindowListener- Parameters:
e- The window event
-
windowDeactivated
public void windowDeactivated(java.awt.event.WindowEvent e)
Does nothing. Called by the system after the window has been deactivated.- Specified by:
windowDeactivatedin interfacejava.awt.event.WindowListener- Parameters:
e- The window event
-
windowDeiconified
public void windowDeiconified(java.awt.event.WindowEvent e)
Does nothing. Called by the system after the window has been deminimized.- Specified by:
windowDeiconifiedin interfacejava.awt.event.WindowListener- Parameters:
e- The window event
-
windowIconified
public void windowIconified(java.awt.event.WindowEvent e)
Does nothing. Called by the system after the window has been minimized.- Specified by:
windowIconifiedin interfacejava.awt.event.WindowListener- Parameters:
e- The window event
-
windowOpened
public void windowOpened(java.awt.event.WindowEvent e)
Does nothing. Called by the system after the window has been opened for the first time.- Specified by:
windowOpenedin interfacejava.awt.event.WindowListener- Parameters:
e- The window event
-
-