Java Reference
In-Depth Information
6. Enter lines 169 through 175 as shown in Figure 10-41 on page 650.
TextPad displays code for the logoutUser() method in the coding window
(Figure 10-47). This logoutUser() method hides the current window, disposes
of its resources, and invokes the callback method, activate(), in the calling
object.
hides current window
logoutUser()
method
callback method
invoked
disposes resources
of current window
FIGURE 10-47
Calling the setVisible() method with a parameter of false hides the current
window. Calling the dispose() method in the logoutUser() method before
invoking the callback method, activate(), releases all of the resources used by
this window and makes any memory used by the window available to the
operating system. Line 174 includes the callback mechanism that calls back to
the activate() method of the caller object, LogonFrame.
Implementing the WindowListener Interface
Because the StockFrame class indicates that it will implement the
WindowListener interface (line 16 of Figure 10-41 on page 648), it must define
the required methods of the interface to be a concrete class. As previously noted,
the WindowListener interface requires seven methods be implemented to handle
each of seven possible Window events. Only two of the methods — the
windowOpened() method and the windowClosing() method — are used by the
StockFrame object. The windowOpened() method in lines 178 through 182
prepares the StockSymbol JTextField for user data entry when the window first is
opened. When the user closes the window, the windowClosing() method in
lines 184 through 187 calls the logoutUser() method, as both methods take the
same action. The remaining methods must be implemented, but are empty and,
therefore, take no action if invoked.
Search WWH ::




Custom Search