|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--Console
The Console is a simple interface for keyboard input and screen output. This "device" allows a programmer to write code for simple text-mode, user interfaces.
The 'screen' is composed of a 25 row by 80 column matrix of character locations. It is divided into two basic sections. Row 25 is reserved for input. When input is requested using one of the read*() methods, any data entered by the user appears on this line. The input may be optionally preceded by a prompt string.
There is an internal cursor that keeps track of the location, in the first (top) 24 rows where characters may be written. The screen coordiates run from 0 to 24 (for rows) and 0 to 79 (for columns). The normal convention is to indicate the row number first (first parameter in most method calls) but the gotoXY() method reverses this order for historical reasons. A program can format the upper screen area in any way desired, for example to produce menus or text-based graphics.
Field Summary | |
static int |
COLS
|
static int |
ROWS
|
Constructor Summary | |
Console()
Constructing a Console device creates a screen, 24 rows by 80 columns of text (ASCII characters). |
Method Summary | |
void |
clearScreen()
Clears all characters from the screen and prints the cleared screen to the monitor. |
void |
gotoXY(int x,
int y)
Sets the screen cursor to locations indicated by x and y parameters. |
void |
initScreen()
Sets up the screen for display. |
static void |
main(java.lang.String[] args)
|
static void |
printPrompt(java.lang.String prompt)
Prints a prompt message to the console input row (row 25). |
void |
printScreen()
This method is called to display the current contents of the screen. |
void |
putChar(char c)
Puts a character in the location determined by the internal cursor. |
void |
putCharAt(char c,
int row,
int col)
Allows the placement of a single ASCII character at any screen location desired. |
void |
putString(java.lang.String s)
Places a String on the screen starting at the current screen cursor location. |
void |
putStringAt(java.lang.String s,
int row,
int col)
Allows the placement of a String at any screen location desired. |
static double |
readDouble(java.lang.String prompt)
Reads a double value input on the input row (row 25). |
static int |
readInt(java.lang.String prompt)
Reads an integer value input on the input row (row 25). |
static java.lang.String |
readLine()
Reads a string input from the console input row (row 25) typed by the user. |
static java.lang.String |
readLine(java.lang.String prompt)
Similar to readLine() but prints a prompt message on the input row (row 25) prior to waiting for user input. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int ROWS
public static final int COLS
Constructor Detail |
public Console()
Method Detail |
public void initScreen()
public void printScreen()
Console c = new Console(); c.putStringAt("Hello World!", 4, 18); c.putStringAt("How are you?", 5, 18); c.printScreen();
public void clearScreen()
public void putCharAt(char c, int row, int col)
public void putChar(char c)
c.gotoXY(22, 5); \\ put cursor at the coordinates 5, 22 putChar('|'); \\
public void putStringAt(java.lang.String s, int row, int col)
public void putString(java.lang.String s)
public void gotoXY(int x, int y)
public static void printPrompt(java.lang.String prompt)
public static java.lang.String readLine()
public static java.lang.String readLine(java.lang.String prompt)
public static int readInt(java.lang.String prompt)
public static double readDouble(java.lang.String prompt)
public static void main(java.lang.String[] args)
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |