Java Reference
In-Depth Information
You also will extend the class, which means that this new Java class will be a
type or subclass of applet. As shown in line 14 of Figure 2-48 on the previous
page, the extends command is added to the class header, along with the name
of the superclass. Recall that a superclass represents a broader, higher category
of a class object, and shares a common structure and behavior with its sub-
classes. In the Welcome to My Day program, Applet is the superclass you will
extend to create the subclass, WelcomeApplet. When a class extends from
another class, it inherits attributes and methods from its superclass. The Wel-
comeApplet subclass will inherit general applet characteristics from the Applet
class, such as the ability to run in a browser window.
Perform the following steps to edit the class name and extend the Applet
class.
To Edit the Class Name and Extend the Applet Class
1. In the TextPad coding window, click after the word, Welcome, in line 5.
Without spacing, type Applet as shown in Figure 2-49.
TextPad displays the comment header with the new file name,
WelcomeApplet.java, in line 5 (Figure 2-49).
new file name
FIGURE 2-49
2. In line 14, click after the word, Welcome, in the class header. Without
pressing the SPACEBAR , type Applet extends Applet to complete the
line.
The new class header is displayed (Figure 2-50). Adding the extends com-
mand instructs the program to consider WelcomeApplet as a subclass of
Applet. You also may change the purpose comment to better reflect the
applet.
Search WWH ::




Custom Search