Java Reference
In-Depth Information
As you learned in Chapter 5, the WindowListener interface requires
that seven methods be implemented. Only two of the methods — the
windowOpened() method in lines 177 through 182 and the windowClosing()
method in lines 183 through 187 — are used by the StockFrame object. The
remaining methods must be implemented in lines 188 through 207, but are
empty and, therefore, take no action if invoked.
The following steps enter code to create the StockFrame class, which uses a
callback mechanism to call the LogonFrame class.
To Create a Callback Mechanism in a Class
1. Create a new TextPad document and save it in the Chapter10 folder, or
a location specified by your instructor, typing StockFrame as the file
name and selecting Java (*.java) as the file type. Enter lines 1 through 26
as shown in Figure 10-41 on page 648. In the comments, insert your
own name as programmer and enter the current date.
TextPad displays code for the initial comments, class header, and instance
variables in the coding window (Figure 10-42). The class implements both
the ActionListener and the WindowListener interfaces. A reference to an
Activator object is declared in line 25.
StockFrame
class header
reference to
Activator object
interfaces
implemented
FIGURE 10-42
2. Enter lines 27 through 60 as shown in Figure 10-41.
TextPad displays code for the constructor (Figure 10-43). The constructor
requires a reference to a User object and to an Activator object.
Search WWH ::




Custom Search