|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object acm.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()
|
|
IODialog(Component owner)
|
Method Summary | |
---|---|
boolean |
getAllowCancel()
|
boolean |
getExceptionOnError()
|
void |
print(String value)
|
void |
println()
|
void |
println(String value)
|
boolean |
readBoolean()
true or false , ignoring case. |
boolean |
readBoolean(String prompt)
|
boolean |
readBoolean(String prompt,
String trueLabel,
String falseLabel)
trueLabel and falseLabel
parameters. |
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 |
setAllowCancel(boolean flag)
flag
parameter. |
void |
setExceptionOnError(boolean flag)
flag
parameter. |
void |
showErrorMessage(String msg)
|
Constructor Detail |
---|
public IODialog()
Usage: | dialog = new IODialog(); |
public IODialog(Component owner)
Usage: | dialog = new IODialog(owner); | ||
Parameter: |
|
Method Detail |
---|
public boolean getAllowCancel()
Usage: | boolean flag = dialog.getAllowCancel(); |
Returns: | The current setting of the error-handling mode (false to retry
on errors; true to raise an exception)
|
public boolean getExceptionOnError()
Usage: | boolean flag = dialog.getExceptionOnError(); |
Returns: | The current setting of the error-handling mode (false to retry
on errors; true to raise an exception)
|
public void print(String value)
print
method is overloaded
so that value
can be of any type.
Usage: | dialog.print(value); | ||
Parameter: |
|
print
in interface IOModel
public void println()
Usage: | dialog.println(); |
println
in interface IOModel
public void println(String value)
println
method is overloaded so that value
can be of any type.
Usage: | dialog.println(value); | ||
Parameter: |
|
println
in interface IOModel
public 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.
Usage: | boolean flag = dialog.readBoolean(); |
Returns: | The value of the input interpreted as a boolean value |
readBoolean
in interface IOModel
public final boolean readBoolean(String prompt)
setExceptionOnError
method.
Usage: | boolean flag = dialog.readBoolean(prompt); | ||
Parameter: |
| ||
Returns: | The value of the input interpreted as a boolean value |
readBoolean
in interface IOModel
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.
Usage: | boolean flag = dialog.readBoolean(prompt); | ||||||
Parameters: |
| ||||||
Returns: | The value of the input interpreted as a boolean value |
readBoolean
in interface IOModel
public final double readDouble()
setExceptionOnError
method.
Usage: | double d = dialog.readDouble(); |
Returns: | The value of the input interpreted as a double
|
readDouble
in interface IOModel
public final double readDouble(double low,
double high)
setExceptionOnError
method.
Usage: | double d = dialog.readDouble(low, high); | ||||
Parameters: |
| ||||
Returns: | The value of the input interpreted as a double
|
readDouble
in interface IOModel
public final double readDouble(String prompt)
setExceptionOnError
method.
Usage: | double d = dialog.readDouble(prompt); | ||
Parameter: |
| ||
Returns: | The value of the input interpreted as a double
|
readDouble
in interface IOModel
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.
Usage: | d = dialog.readDouble(prompt, low, high); | ||||||
Parameters: |
| ||||||
Returns: | The value of the input interpreted as a double
|
readDouble
in interface IOModel
public final int readInt()
setExceptionOnError
method.
Usage: | int n = dialog.readInt(); |
Returns: | The value of the input interpreted as a decimal integer |
readInt
in interface IOModel
public final int readInt(int low,
int high)
setExceptionOnError
method.
Usage: | int n = dialog.readInt(low, high); | ||||
Parameters: |
| ||||
Returns: | The value of the input interpreted as a decimal integer |
readInt
in interface IOModel
public final int readInt(String prompt)
setExceptionOnError
method.
Usage: | int n = dialog.readInt(prompt); | ||
Parameter: |
| ||
Returns: | The value of the input interpreted as a decimal integer |
readInt
in interface IOModel
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.
Usage: | int n = dialog.readInt(prompt, low, high); | ||||||
Parameters: |
| ||||||
Returns: | The value of the input interpreted as a decimal integer |
readInt
in interface IOModel
public final String readLine()
Usage: | String str = dialog.readLine(); |
Returns: | The next line of input as a String
|
readLine
in interface IOModel
public String readLine(String prompt)
Usage: | String str = dialog.readLine(prompt); | ||
Parameter: |
| ||
Returns: | The next line of input as a String
|
readLine
in interface IOModel
public 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.
Usage: | dialog.setAllowCancel(flag); | ||
Parameter: |
|
public 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.
Usage: | dialog.setExceptionOnError(flag); | ||
Parameter: |
|
public void showErrorMessage(String msg)
Usage: | dialog.showErrorMessage(msg); | ||
Parameter: |
|
showErrorMessage
in interface IOModel
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |