|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectacm.program.CommandLineProgram
public class CommandLineProgram
This class simulates the functionality of a ConsoleProgram
in an environment that lacks a graphics context. As of JDK 1.4, it is
illegal even to instantiate an applet in a non-graphics environment
(called "headless" in the Java terminology), which means that the program
can no longer extend Applet or JApplet. This
class creates a stripped-down program class that duplicates the operation
of a ConsoleProgram using the standard I/O streams.
| Field Summary | |
|---|---|
String |
CENTER
|
String |
EAST
|
String |
NORTH
|
String |
SOUTH
|
String |
WEST
|
| Method Summary | |
|---|---|
void |
actionPerformed(ActionEvent e)
|
void |
addActionListeners()
ActionListener to every button in
the structure that does not have a listener already. |
void |
addActionListeners(ActionListener listener)
|
void |
addExitHook(Object obj)
exit method in the
specified object before exiting. |
void |
checkIfHeadless(String className)
|
void |
exit()
|
IOConsole |
getConsole()
|
IODialog |
getDialog()
|
IOModel |
getInputModel()
IOModel used for program input, which will
typically be either the default IOConsole or IODialog object. |
IOModel |
getOutputModel()
IOModel used for program output, which will
typically be either the default IOConsole or IODialog object. |
BufferedReader |
getReader()
BufferedReader whose input comes from the console. |
String |
getTitle()
|
PrintWriter |
getWriter()
PrintWriter whose output is directed to the console. |
void |
init()
|
void |
keyPressed(KeyEvent e)
|
void |
keyReleased(KeyEvent e)
|
void |
keyTyped(KeyEvent e)
|
void |
main(String[] args)
MyClass is the name of the program class: |
void |
menuAction(String cmd)
|
void |
mouseClicked(MouseEvent e)
|
void |
mouseDragged(MouseEvent e)
|
void |
mouseEntered(MouseEvent e)
GObject). |
void |
mouseExited(MouseEvent e)
GObject). |
void |
mouseMoved(MouseEvent e)
|
void |
mousePressed(MouseEvent e)
|
void |
mouseReleased(MouseEvent e)
|
void |
print(String value)
|
void |
println()
|
void |
println(String value)
|
boolean |
readBoolean()
true or false). |
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 |
run()
|
void |
setConsole(IOConsole console)
|
void |
setTitle(String title)
|
void |
showErrorMessage(String msg)
|
void |
start(String[] args)
|
| Field Detail |
|---|
public static final String CENTER
public static final String EAST
public static final String NORTH
public static final String SOUTH
public static final String WEST
| Method Detail |
|---|
public void actionPerformed(ActionEvent e)
actionPerformed in interface ActionListener
public void addActionListeners()ActionListener to every button in
the structure that does not have a listener already.
Usage: | addActionListeners(); |
public void addActionListeners(ActionListener listener)Usage: | addActionListeners(listener); | ||
Parameter: |
|
public void addExitHook(Object obj)exit method in the
specified object before exiting.
Usage: | program.addExitHook(obj); |
public static void checkIfHeadless(String className)Usage: | CommandLineProgram.checkIfHeadless(className); | ||
Parameter: |
|
public void exit()super.exit() at the end of their processing.
Usage: | program.exit(); |
public IOConsole getConsole()Usage: | IOConsole console = program.getConsole(); |
Returns: | The IOConsole object used for this program
|
public IODialog getDialog()Usage: | IODialog dialog = program.getDialog(); |
Returns: | The IODialog object used for this program
|
public IOModel getInputModel()IOModel used for program input, which will
typically be either the default IOConsole or IODialog object.
Usage: | IOModel io = program.getInputModel(); |
Returns: | The IOModel used for program input
|
public IOModel getOutputModel()IOModel used for program output, which will
typically be either the default IOConsole or IODialog object.
Usage: | IOModel io = program.getOutputModel(); |
Returns: | The IOModel used for program output
|
public BufferedReader getReader()BufferedReader whose input comes from the console.
Usage: | BufferedReader rd = getReader(); |
Returns: | A Reader for use with this console
|
public String getTitle()Usage: | String title = getTitle(); |
Returns: | The title in use for this program |
public PrintWriter getWriter()PrintWriter whose output is directed to the console.
Usage: | PrintWriter wr = getWriter(); |
Returns: | A PrintWriter for use with this console
|
public void init()init method. This method is used only for certain styles
of application development that have their roots in the applet world;
other styles will not ordinarily use or override this method.
Usage: | program.init(); |
public void keyPressed(KeyEvent e)
keyPressed in interface KeyListener
public void keyReleased(KeyEvent e)
keyReleased in interface KeyListener
public void keyTyped(KeyEvent e)
keyTyped in interface KeyListener
public static void main(String[] args)MyClass is the name of the program class:
public static void main(String[] args) {
new MyClass().start();
}
If the program needs the command line arguments, the args
array can be passed to the start method and then retrieved
using the getArgumentArray method.
Parameter: |
|
public void menuAction(String cmd)
public void mouseClicked(MouseEvent e)mouseClicked
is always preceded by both a mousePressed and a
mouseReleased event for the same source.
mouseClicked in interface MouseListener
public void mouseDragged(MouseEvent e)mouseDragged call is always preceded by a
mousePressed call for the same source. If the
mouse is pressed elsewhere and then enters a source with
the button down, no drag event occurs. Moreover, once the
mouse button goes down in a particular source, only that
source will receive mouse events until the button goes up.
Those events, moreover, are reported even in the mouse
travels outside the domain of the object.
mouseDragged in interface MouseMotionListener
public void mouseEntered(MouseEvent e)GObject).
mouseEntered in interface MouseListener
public void mouseExited(MouseEvent e)GObject).
mouseExited in interface MouseListener
public void mouseMoved(MouseEvent e)
mouseMoved in interface MouseMotionListener
public void mousePressed(MouseEvent e)
mousePressed in interface MouseListener
public void mouseReleased(MouseEvent e)
mouseReleased in interface MouseListener
public void print(String value)print method is overloaded so that
value can be of any type.
Usage: | program.print(value); | ||
Parameter: |
|
print in interface IOModel
public void println()Usage: | program.println(); |
println in interface IOModel
public void println(String value)println method is
overloaded so that value can be of any type.
Usage: | program.println(value); | ||
Parameter: |
|
println in interface IOModel
public final boolean readBoolean()true or false).
The input must match one of these strings, 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 = program.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 = program.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)readBoolean ordinarily offers the user a chance
to reenter the data, although this behavior can be changed using the
setExceptionOnError method.
Usage: | boolean flag = program.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 = program.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 = program.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 = program.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 = program.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 = program.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 = program.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 = program.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 = console.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 = program.readLine(); |
Returns: | The next line of input as a String
|
readLine in interface IOModel
public String readLine(String prompt)Usage: | String str = program.readLine(prompt); | ||
Parameter: |
| ||
Returns: | The next line of input as a String
|
readLine in interface IOModel
public void run()run so that it contains the code for your application.
run in interface Runnable
public void setConsole(IOConsole console)Usage: | program.setConsole(console); | ||
Parameter: |
|
public void setTitle(String title)Usage: | setTitle(title); | ||
Parameter: |
|
public void showErrorMessage(String msg)Usage: | showErrorMessage(msg); | ||
Parameter: |
|
showErrorMessage in interface IOModel
public void start(String[] args)Usage: | program.start(args); | ||
Parameter: |
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||