See: Description
Class | Description |
---|---|
ConsoleProgram |
This class is a standard subclass of
Program that installs a console in
the window. |
DialogProgram |
This class is a standard subclass of
Program that takes its input from a
IODialog object. |
GraphicsProgram |
This class is a standard subclass of
Program whose principal window is
used for drawing graphics. |
Program |
This class is the superclass for all executable programs in the
acm.program package. |
ProgramMenuBar |
This class standardizes the menu bars used in the ACM program package.
|
Program
System#in
and
System#out
.ConsoleProgram
Program
but fills the program
frame with an interactive console (as defined in the IOConsole
class.DialogProgram
Program
class so that input operations are performed using the
IODialog
class.acm.program.CommandLineProgram
ConsoleProgram
but uses
System#in
and System#out
instead of an
IOConsole
. This class is typically used only for Java programs
that are invoked from a command line and make no use of Javas graphical
capabilities.
The principal advantages of using the Program
class are:
acm.program
package moves students away from the imperative
style of public static void main
into a more
pedagogically defensible framework in which students are always working in
the context of an object.
Program
class allows Java applications to double
as applets, thereby making it possible for instructors to use either paradigm
in a consistent way. Even for those instructors that choose to focus on the
application paradigm, using the Program
class makes it
much easier for students to make their code available on the web. Moreover,
because the Program
class is defined to be a subclass of
Applet
, applications that run in that domain can take advantage
of such applet-based features as loading audio clips and images from the code
base.
Program
class includes several features that make
instruction easier, such as the definition of standard menu bars that support
operations like printing and running programs with a test script.
acm.program
package offer a compelling
example of an inheritance hierarchy that introductory students can understand
and appreciate right from the beginning of their first course.
In most environments, the only thing students need to do to create a new
program is to define a Program
subclass that implements a
run
method. For example, the following class definition creates
a traditional, stream-oriented program that reads in two integers and
computes their sum:
public class Add2 extends ConsoleProgram {
public void run() {
println("This program adds two numbers.");
int n1 = readInt("Enter n1: ");
int n2 = readInt("Enter n2: ");
int total = n1 + n2;
println("The total is " + total + ".");
}
}