Java Reference
In-Depth Information
Table 5-4 Methods in the Reservations Class
METHOD NAME
PURPOSE
Reservations()
Set layout of the Frame
Instantiate TextArea components to display default settings
Add components to the user interface
Add listeners to all necessary components and to the window
main()
Create an instance of Reservations object
Set attributes of the Frame
actionPerformed()
Check to see if the hidden Checkbox still is selected
Check to make sure a room is available
clearFields()
Reset all input fields
First, the program will use a constructor method named
Reservations() to create a Frame and add various components
to it. A constructor method is a programmer-defined method
that is called when creating an object to ensure that all associated
variables are initialized properly. Constructor methods have
the same name as the object class they are creating.
Constructor methods have no return data type; they
have the implicit type of the object that they
construct, creating an instance of the object
internally. You have called constructors of
objects such as Labels and Buttons in
previous chapters using the = new notation, which
is the standard notation to instantiate or construct an
object of a class. In this chapter, however, you will
write a new constructor method for
the Reservations class to allow other
classes to extend the Reservations
class. The main() method will
instantiate the Frame and
set its attributes.
The actionPerformed()
method is executed
when a user clicks the
Book Room button.
Figure 5-4 displays a
flowchart for the
actionPerformed() method,
which checks to see if the hidden
Checkbox still is selected and then
checks to make sure a room that
meets the user criteria is available
for booking.
a c tionPerformed()
Method
Start
Is hidden
Checkbox still
selected?
No
Yes
Call a method
to look for an
available room
Display
error
message
Is a room
available?
No
Yes
Set background
color of booked
room
Is smoking
Checkbox
selected?
No
Yes
Display
nonsmoking is
full message
Display
smoking is
full message
Set text of
booked room
Call the
clearFields()
method to clear
the input fields
Set hidden
Checkbox to true
End
FIGURE 5-4
 
Search WWH ::




Custom Search