|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--acm.io.IOConsole
public class IOConsole extends Container implements IOModel
The IOConsole class makes it easier to interact with the user using text-based input and output in the style of a traditional console. Given a IOConsole object, you can write output to that console using the print and println methods, just as you would for the standard output stream. To request input from the user, the most common methods are
A IOConsole object is a lightweight component and must be added to an installed Frame or JFrame before it becomes visible on the screen. The usual strategy for including a console in a frame is to use the ConsoleProgram mechanism in the acm.program package. The operation of the IOConsole class is illustrated by the following test method, which generates the session shown on the right. The user input appears in blue, just as it does in the console window.
|
![]() |
Field Summary | |
IOConsole | SYSTEM_CONSOLE |
Constructor Summary |
IOConsole() |
Method Summary | |
void | clear() |
boolean | getExceptionOnError() |
BufferedReader | getInputScript() |
BufferedReader | getReader() |
PrintWriter | getWriter() |
void | print(String value) |
void | println() |
void | println(String value) |
boolean | readBoolean() |
boolean | readBoolean(String prompt) |
boolean | readBoolean(String prompt,
String trueLabel,
String falseLabel) |
double | readDouble() |
double | readDouble(double low,
double high) |
double | readDouble(String prompt) |
double | readDouble(String prompt,
double low,
double high) |
int | readInt() |
int | readInt(int low,
int high) |
int | readInt(String prompt) |
int | readInt(String prompt,
int low,
int high) |
String | readLine() |
String | readLine(String prompt) |
void | setBackground(Color color) |
void | setExceptionOnError(boolean flag) |
void | setFont(Font font) |
void | setFont(String str) |
void | setForeground(Color color) |
void | showErrorMessage(String msg) |
Field Detail |
public static final IOConsole SYSTEM_CONSOLE
Constructor Detail |
public IOConsole()
Usage: | IOConsole console = new IOConsole(); |
Method Detail |
public void clear()
Usage: | console.clear(); |
public boolean getExceptionOnError()
Usage: | boolean flag = console.getExceptionOnError(); |
Returns: | The current setting of the error-handling mode (false to retry on errors; true to raise an exception) |
public BufferedReader getInputScript()
Usage: | BufferedReader rd = console.getInputScript(); |
Returns: | The reader representing the current input script |
public BufferedReader getReader()
Usage: | BufferedReader rd = console.getReader(); |
Returns: | A BufferedReader that reads from this console |
public PrintWriter getWriter()
Usage: | PrintWriter wr = console.getWriter(); |
Returns: | A PrintWriter that writes to this console |
public void print(String value)
Usage: | console.print(value); | ||
Parameter: |
| ||
Specified by: | print in interface IOModel |
public void println()
Usage: | console.println(); |
Specified by: | println in interface IOModel |
public void println(String value)
Usage: | console.println(value); | ||
Parameter: |
| ||
Specified by: | println in interface IOModel |
public final boolean readBoolean()
Usage: | boolean flag = console.readBoolean(); |
Returns: | The value of the input interpreted as a boolean value |
Specified by: | readBoolean in interface IOModel |
public final boolean readBoolean(String prompt)
Usage: | boolean flag = console.readBoolean(prompt); | ||
Parameter: |
| ||
Returns: | The value of the input interpreted as a boolean value | ||
Specified by: | readBoolean in interface IOModel |
public boolean readBoolean(String prompt,
String trueLabel,
String falseLabel)
Usage: | boolean flag = console.readBoolean(prompt); | ||||||
Parameters: |
| ||||||
Returns: | The value of the input interpreted as a boolean value | ||||||
Specified by: | readBoolean in interface IOModel |
public final double readDouble()
Usage: | double d = console.readDouble(); |
Returns: | The value of the input interpreted as a double |
Specified by: | readDouble in interface IOModel |
public final double readDouble(double low,
double high)
Usage: | double d = console.readDouble(low, high); | ||||
Parameters: |
| ||||
Returns: | The value of the input interpreted as a double | ||||
Specified by: | readDouble in interface IOModel |
public final double readDouble(String prompt)
Usage: | double d = console.readDouble(prompt); | ||
Parameter: |
| ||
Returns: | The value of the input interpreted as a double | ||
Specified by: | readDouble in interface IOModel |
public double readDouble(String prompt,
double low,
double high)
Usage: | d = console.readDouble(prompt, low, high); | ||||||
Parameters: |
| ||||||
Returns: | The value of the input interpreted as a double | ||||||
Specified by: | readDouble in interface IOModel |
public final int readInt()
Usage: | int n = console.readInt(); |
Returns: | The value of the input interpreted as a decimal integer |
Specified by: | readInt in interface IOModel |
public final int readInt(int low,
int high)
Usage: | int n = console.readInt(low, high); | ||||
Parameters: |
| ||||
Returns: | The value of the input interpreted as a decimal integer | ||||
Specified by: | readInt in interface IOModel |
public final int readInt(String prompt)
Usage: | int n = console.readInt(prompt); | ||
Parameter: |
| ||
Returns: | The value of the input interpreted as a decimal integer | ||
Specified by: | readInt in interface IOModel |
public int readInt(String prompt,
int low,
int high)
Usage: | int n = console.readInt(prompt, low, high); | ||||||
Parameters: |
| ||||||
Returns: | The value of the input interpreted as a decimal integer | ||||||
Specified by: | readInt in interface IOModel |
public final String readLine()
Usage: | String str = console.readLine(); |
Returns: | The next line of input as a String |
Specified by: | readLine in interface IOModel |
public String readLine(String prompt)
Usage: | String str = console.readLine(prompt); | ||
Parameter: |
| ||
Returns: | The next line of input as a String | ||
Specified by: | readLine in interface IOModel |
public void setBackground(Color color)
Usage: | console.setBackground(color); | ||
Parameter: |
|
public void setExceptionOnError(boolean flag)
Usage: | console.setExceptionOnError(flag); | ||
Parameter: |
|
public void setFont(Font font)
Usage: | console.setFont(font); | ||
Parameter: |
|
public void setFont(String str)
familycode>-stylecode>-size where both style and size are optional. If any of these parts are specified as an asterisk, the existing value is retained.
Usage: | console.setFont(str); | ||
Parameter: |
|
public void setForeground(Color color)
Usage: | console.setForeground(color); | ||
Parameter: |
|
public void showErrorMessage(String msg)
Usage: | console.showErrorMessage(msg); | ||
Parameter: |
| ||
Specified by: | showErrorMessage in interface IOModel |
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |