|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
javax.swing.JApplet
acm.program.Program
public abstract class Program
This class is the superclass for all executable
programs in the acm.program package. Its principal
role is to unify the concepts of applets and applications in a single
class, although it also provides applications with many other useful
facilities not traditionally available in applications.
In many programming environments, objects that are specific instances
of a Program subclass will run automatically without any
special action on your part. For maximum portability, you might want
to define a static main method as described in the comments
for the standard implementation of main.
| 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 |
exit()
|
Dimension |
getCentralRegionSize()
|
IOConsole |
getConsole()
|
IODialog |
getDialog()
|
IOModel |
getInputModel()
IOModel used for program input, which will
ordinarily be the console. |
ProgramMenuBar |
getMenuBar()
|
IOModel |
getOutputModel()
IOModel used for program output, which will
ordinarily be the console. |
BufferedReader |
getReader()
BufferedReader whose input comes from the console. |
String |
getTitle()
|
PrintWriter |
getWriter()
PrintWriter whose output is directed to the console. |
void |
init()
run method is called. |
void |
keyPressed(KeyEvent e)
|
void |
keyReleased(KeyEvent e)
|
void |
keyTyped(KeyEvent e)
|
void |
main(String[] args)
MyClass is the name of the program class: |
boolean |
menuAction(ActionEvent e)
|
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 |
pause(double milliseconds)
|
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 |
setDialog(IODialog dialog)
|
void |
setInputModel(IOModel io)
|
void |
setOutputModel(IOModel io)
|
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 void exit()super.exit() at the end of their processing.
Usage: | program.exit(); |
public Dimension getCentralRegionSize()Returns: | The size of the central region |
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
ordinarily be the console.
Usage: | IOModel io = program.getInputModel(); |
Returns: | The IOModel used for program input
|
public ProgramMenuBar getMenuBar()createMenuBar factory method.
Usage: | ProgramMenuBar mbar = getMenuBar(); |
Returns: | The menu bar in use for this program |
public IOModel getOutputModel()IOModel used for program output, which will
ordinarily be the console.
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()run method is called. Subclasses can override this
method to perform any initialization code that would ordinarily
be included in an applet init method. In general,
subclasses will override init in GUI-based programs
where the program simply sets up an initial state and then waits
for events from the user. The run method is required
for applications in which there needs to be some control thread
while the program runs, as in a typical animation.
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 boolean menuAction(ActionEvent e)
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 pause(double milliseconds)Thread.sleep, this method never throws an
exception.
Usage: | program.pause(milliseconds); | ||
Parameter: |
|
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 method is required for applications that have
a thread of control that runs even in the absence of user actions,
such as a program that uses console interation or that involves
animation. GUI-based programs that operate by setting up an initial
configuration and then wait for user events usually do not specify a
run method and supply a new definition for init
instead.
run in interface Runnable
public void setConsole(IOConsole console)Usage: | program.setConsole(console); | ||
Parameter: |
|
public void setDialog(IODialog dialog)Usage: | program.setDialog(dialog); | ||
Parameter: |
|
public void setInputModel(IOModel io)Usage: | program.setInputModel(io); | ||
Parameter: |
|
public void setOutputModel(IOModel io)Usage: | program.setOutputModel(io); | ||
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 | ||||||||