Java Reference
In-Depth Information
The following step enters code for the WindowListener interface in the
StockFrame class.
To Implement the WindowListener Interface
1. Enter lines 176 through 208 as shown in Figure 10-41 on page 650.
Save and compile the StockFrame class.
TextPad displays code in the coding window for the seven methods required
to implement the WindowListener interface (Figure 10-48). The win-
dowOpened() method and windowClosing() method contain code. The
remaining methods are empty and, therefore, take no action if invoked.
windowOpened()
method prepares
StockSymbol
JTextField for
initial data entry
empty methods
windowClosed()
method calls
logoutUser()
method
FIGURE 10-48
Now that the StockFrame class is complete, the LogonFrame class that uses
it can be created. Figure 10-49 displays the code for the LogonFrame class. As
shown in line 16, the LogonFrame class implements the Activator interface
created earlier. Doing so allows the LogonFrame to pass a reference to itself to
the StockFrame constructor and allows the StockFrame object to call back to
the activate() method in the LogonFrame object. Line 16 also implements the
ActionListener interface to listen for mouse clicks on a button, once the listener
interface is registered with a button. Lines 16 through 158 create the user
interface and functionality for the LogonFrame window, including displaying the
window centered, determining if a user already is in the collection, and adding a
user to the collection of users. As this is very similar to earlier tasks, this code is
provided on the Student Data Disk. Note that line 18 defines the variable,
maxUsers, which is the maximum number of users that can be added simultane-
ously to the test application. Note also that line 10 imports a specific class to
support the creation of a TitledBorder object. A Border is an object used to draw
titles, empty spaces, lines, or fancy edges in the area around a component. A
 
Search WWH ::




Custom Search