|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectacm.io.IODialog
public class IODialog
The IODialog class provides a simple, dialog-based mechanism
for interacting with the user. It is therefore similar to the
JOptionPane facility in Swing (which it uses in the implementation).
The differences between the models are
IODialog mechanism is considerably simpler, mostly
because it does not try to be as general.
IODialog mechanism does not use static methods; clients
instantiate an IODialog object and make calls on that object,
thereby emphasizing the object-oriented idea.
IODialog class works even if Swing is not available.
IODialog are intentionally the
same as those for the IOConsole class so
that clients can substitute one model for another without making source changes.
The input methods are therefore
For example, the following code pops up a dialog box and
allows the user to enter an integer:
IODialog dialog = new IODialog();
int n = dialog.readInt("Enter an integer: ");
| Constructor Summary | |
|---|---|
IODialog()
Instantiates a new IODialog object that can then be used for dialog-based input and output. |
|
IODialog(Component owner)
Instantiates a new IODialog object that can then be used for dialog-based input and output. |
|
| Method Summary | |
|---|---|
protected acm.io.DialogModel |
createModel()
Creates the input dialog model in Swing or AWT style, as appropriate. |
boolean |
getAllowCancel()
Returns the state of the cancellation mode. |
IOConsole |
getAssociatedConsole()
Returns the associated console for the dialog. |
boolean |
getExceptionOnError()
Returns the state of the error-handling flag. |
void |
print(boolean x)
Makes sure that print can display a boolean. |
void |
print(char x)
Makes sure that print can display a char. |
void |
print(double x)
Makes sure that print can display a double. |
void |
print(float x)
Makes sure that print can display a float. |
void |
print(int x)
Makes sure that print can display an int. |
void |
print(long x)
Makes sure that print can display a long. |
void |
print(Object x)
Makes sure that print can display an Object. |
void |
print(String value)
Displays the argument value, allowing for the possibility of more output in the same dialog. |
void |
println()
Completes the output line and displays the dialog. |
void |
println(boolean x)
Makes sure that println can display a boolean. |
void |
println(char x)
Makes sure that println can display a char. |
void |
println(double x)
Makes sure that println can display a double. |
void |
println(float x)
Makes sure that println can display a float. |
void |
println(int x)
Makes sure that println can display an int. |
void |
println(long x)
Makes sure that println can display a long. |
void |
println(Object x)
Makes sure that println can display an Object. |
void |
println(String value)
Adds the value to the current output line and then displays the dialog. |
boolean |
readBoolean()
Reads and returns a boolean value from the user, which must match either true or false, ignoring case. |
boolean |
readBoolean(String prompt)
Prompts the user to enter a boolean value, which is then returned as the value of this method. |
boolean |
readBoolean(String prompt,
String trueLabel,
String falseLabel)
Prompts the user to enter a value, which is interpreted as a boolean value by matching it against the trueLabel and falseLabel
parameters. |
double |
readDouble()
Reads and returns a double-precision value from the user. |
double |
readDouble(double low,
double high)
Reads and returns a double-precision value from the user, which is constrained to be within the specified inclusive range. |
double |
readDouble(String prompt)
Prompts the user to enter an double-precision number, which is then returned as the value of this method. |
double |
readDouble(String prompt,
double low,
double high)
Prompts the user to enter an double-precision number, which is then returned as the value of this method. |
int |
readInt()
Reads and returns an integer value from the user. |
int |
readInt(int low,
int high)
Reads and returns an integer value from the user, which is constrained to be within the specified inclusive range. |
int |
readInt(String prompt)
Prompts the user to enter an integer, which is then returned as the value of this method. |
int |
readInt(String prompt,
int low,
int high)
Prompts the user to enter an integer, which is then returned as the value of this method. |
String |
readLine()
Reads and returns a line of input from the dialog, without including the end-of-line characters that terminate the input. |
String |
readLine(String prompt)
Prompts the user to enter a single character, which is then returned as the value of this method. |
void |
setAllowCancel(boolean flag)
Sets the cancellation mode of the dialog as specified by the flag
parameter. |
void |
setAssociatedConsole(IOConsole console)
Establishes an associated console for the dialog. |
void |
setExceptionOnError(boolean flag)
Sets the error-handling mode of the dialog as specified by the flag
parameter. |
void |
showErrorMessage(String msg)
Displays the error message in an error dialog. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public IODialog()
public IODialog(Component owner)
owner - A Component used as the owner of created dialogs| Method Detail |
|---|
protected acm.io.DialogModel createModel()
public boolean getAllowCancel()
false to retry
on errors; true to raise an exception)public IOConsole getAssociatedConsole()
public boolean getExceptionOnError()
false to retry
on errors; true to raise an exception)public final void print(boolean x)
print can display a boolean.
print in interface IOModelpublic final void print(char x)
print can display a char.
print in interface IOModelpublic final void print(double x)
print can display a double.
print in interface IOModelpublic final void print(float x)
print can display a float.
print in interface IOModelpublic final void print(int x)
print can display an int.
print in interface IOModelpublic final void print(long x)
print can display a long.
print in interface IOModelpublic final void print(Object x)
print can display an Object.
print in interface IOModelpublic void print(String value)
print method is overloaded
so that value can be of any type.
print in interface IOModelvalue - The value to be displayedpublic void println()
println in interface IOModelpublic final void println(boolean x)
println can display a boolean.
println in interface IOModelpublic final void println(char x)
println can display a char.
println in interface IOModelpublic final void println(double x)
println can display a double.
println in interface IOModelpublic final void println(float x)
println can display a float.
println in interface IOModelpublic final void println(int x)
println can display an int.
println in interface IOModelpublic final void println(long x)
println can display a long.
println in interface IOModelpublic final void println(Object x)
println can display an Object.
println in interface IOModelpublic void println(String value)
println method is overloaded so that value
can be of any type.
println in interface IOModelvalue - The value to be displayedpublic final boolean readBoolean()
true or false, ignoring case.
If the user types a value that is not one of these possibilities,
the method ordinarily offers the user a chance to reenter the data,
although this behavior can be changed using the
setExceptionOnError method.
readBoolean in interface IOModelpublic final boolean readBoolean(String prompt)
setExceptionOnError method.
readBoolean in interface IOModelprompt - The prompt string to display to the user
public boolean readBoolean(String prompt,
String trueLabel,
String falseLabel)
trueLabel and falseLabel
parameters. If the user types a value that is not one of the two choices,
readBoolean ordinarily offers the user a chance
to reenter the data, although this behavior can be changed using the
setExceptionOnError method.
readBoolean in interface IOModelprompt - The prompt string to display to the usertrueLabel - The label for the button indicating truefalseLabel - The label for the button indicating false
public final double readDouble()
setExceptionOnError method.
readDouble in interface IOModeldouble
public final double readDouble(double low,
double high)
setExceptionOnError method.
readDouble in interface IOModellow - The lowest value in the permitted rangehigh - The highest value in the permitted range
doublepublic final double readDouble(String prompt)
setExceptionOnError method.
readDouble in interface IOModelprompt - The prompt string to display to the user
double
public double readDouble(String prompt,
double low,
double high)
low and high. If the user types a value
that is not a legal number, the method ordinarily offers the user a chance
to reenter the data, although this behavior can be changed using the
setExceptionOnError method.
readDouble in interface IOModelprompt - The prompt string to display to the userlow - The lowest value in the permitted rangehigh - The highest value in the permitted range
doublepublic final int readInt()
setExceptionOnError method.
readInt in interface IOModel
public final int readInt(int low,
int high)
setExceptionOnError method.
readInt in interface IOModellow - The lowest value in the permitted rangehigh - The highest value in the permitted range
public final int readInt(String prompt)
setExceptionOnError method.
readInt in interface IOModelprompt - The prompt string to display to the user
public int readInt(String prompt,
int low,
int high)
low and high. If the user types a value that
is not a legal integer or is outside the specified range, the method
ordinarily offers the user a chance to reenter the data,
although this behavior can be changed using the
setExceptionOnError method.
readInt in interface IOModelprompt - The prompt string to display to the userlow - The lowest value in the permitted rangehigh - The highest value in the permitted range
public final String readLine()
readLine in interface IOModelStringpublic String readLine(String prompt)
readLine in interface IOModelprompt - The prompt string to display to the user
Stringpublic void setAllowCancel(boolean flag)
flag
parameter. If flag is false (which is the default),
the input methods do not include a "Cancel" button. If this value is set to
to true, a "Cancel" button appears, which throws a
CancelledException
if it is invoked.
flag - false to remove "Cancel" button; true to enable itpublic void setAssociatedConsole(IOConsole console)
null and the console is reading from an input stream,
then the dialog methods use the console for input instead of the dialog.
console - The associated consolepublic void setExceptionOnError(boolean flag)
flag
parameter. If flag is false (which is the default), the
input methods give the user a chance to retry after erroneous input. If this
value is set to true, illegal input raises an
ErrorException instead.
flag - false to retry on errors; true to raise an exceptionpublic void showErrorMessage(String msg)
showErrorMessage in interface IOModelmsg - The error msg to be displayed
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||