Java Reference
In-Depth Information
Notice that the LogonFrame class also needs to have a WindowListener to
listen for the user closing the window, much as the StockFrame class did for itself.
When the user closes the LogonFrame window, the application terminates by exit-
ing, or returning control, to the operating system. The LogonFrame class, however,
does not implement the WindowListener interface. Instead, it uses an adapter class,
WindowAdapter , to be the listener. It then uses the WindowAdapter object to
override the windowClosing() method, as this is the only method that is needed
by the LogonFrame class. Lines 85 through 87 in Figure 10-49 on page 658 in the
LogonFrame class create a new WindowAdapter object and override the
windowClosing() method.
Because the WindowAdapter is referenced only when adding it as the lis-
tener, no reference variable is needed when the WindowAdapter object is created.
An object created without a reference variable is called an anonymous object .
It is common to see such objects used in Java programs, particularly with respect
to larger interfaces where only a single method is needed, such as with establish-
ing a WindowListener object to listen for the closing of a window.
All of the necessary classes now are defined and compiled. To run the test
application, a class with a main() method is required. Figure 10-53 displays the
code for the StockListDemo class. The only purpose of this StockListDemo class
is to provide an entry point for executing the application, which consists of a
LogonFrame class and a StockFrame class. As shown in Figure 10-53, the
StockListDemo class contains only a main() method, which creates and activates
a LogonFrame object. The following step creates the StockListDemo class.
FIGURE 10-53
 
Search WWH ::




Custom Search