Java Reference
In-Depth Information
The following step enters the code to set the layout managers and add
components to the Reservations() constructor method.
To Enter Code for the Reservations() Constructor Method
1. Enter the code as shown in Figure 5-27 on page 347.
The TextPad window displays the new code (Figure 5-28).
constructor
method header
layouts assigned
to Panels
for loop to assign
room array
attributes
Choice
component
populated
Panels assigned
to BorderLayout
regions
FIGURE 5-28
The Reservations() constructor method shown in Figure 5-28 defines the
layout manager, BorderLayout; adds components to three Panels; constructs a list
in the Choice component; and positions each Panel in a BorderLayout region.
Window Event-Handling Methods
The JVM, or Java Virtual Machine, is the run-time interpreter portion of the Java
SDK. In windowed applications, the JVM handles building the Frame, title bar,
and window control buttons in the title bar, based on the native environment of
the user's machine. To allow the user to interact with the Frame, or window, the
Frame has some inherent events that minimize, maximize, or close the window.
Figure 5-29 on the next page displays the code to add a WindowListener for
the Frame. Java's addWindowListener() method , which begins in line 83, regis-
ters the listener with the Frame. When you register a listener with a Frame, you
connect two objects so that events from one object, the Frame, are sent to the
other object, the listener. The listener tells the Frame object to listen for such
events and respond accordingly.
 
Search WWH ::




Custom Search