Java Reference
In-Depth Information
These components will be inserted into a Frame , which is an AWT component
that serves as a container for a collection of graphical AWT components. A Frame,
which is similar to a window with a title bar and border, utilizes methods to set its
size, title bar caption, and visibility, among other attributes. In this application, the
Frame title bar will display the title, Reserve a Party Room. As the program is
created, the chapter steps will discuss organizing the Frame and placement of the
components.
Within the Frame, the TextArea, TextField, Choice, Checkbox, and Button
components will be placed within one of three Panels. A Panel is an AWT com-
ponent that serves as an invisible container to further refine the arrangement of
components within another container, such as a Frame. A Panel is similar to a
Frame in that it may contain other components, but it does not have a title bar
or any automatic features, such as borders.
PROGRAM DESIGN Once you have designed the interface, the next step is
to design the logic to solve the problem and create the desired results. The pro-
gramming required in the Reservations program involves the capability to create
room objects in memory. Using a graphical user interface, a user should be able
to interact with the program to change the state of a room object, store data
about the room object, and display that data. Toward that end, the program
solution will contain two classes: one class named Reservations, to create the
user interface, and another named Rooms, to create and manipulate a room
object. The Reservations class is considered a driver class — the term used to
specify a class that instantiates other classes and calls appropriate methods.
The first task of the Reservations class is to display the Reservations interface
that allows for user input. In general, windowed application programs, similar
to their applet counterparts, are coded in three basic stages: (1) constructing the
components; (2) adding them to the interface; and (3) programming the
functionality of the components.
Table 5-3 displays a list of the components and variables used in the
Reservations class. Sometimes called a variable dictionary , programmers use
this kind of tool to ensure consistent use of variables and provide a reference for
other programmers. This reference tool is especially useful when multiple pro-
grammers are working on developing a complex Java program with many
classes, components, and variables.
Table 5-3 Components and Variables Used in the Reservations Class
VARIABLE NAME
DATA TYPE OR COMPONENT
PURPOSE
args
String
References any variable passed to the main() method
available
int
Identifies the value returned by the Rooms object; represents
the room number of the first available room (a zero value will
indicate no room available)
bookButton
Button
Calls the bookRoom() method from the Rooms class when the
Button is clicked
buttonPanel
Panel
Serves as a container to hold and position the Button
(continued)
 
Search WWH ::




Custom Search