Describing similar things |
The class we "extend" is the class that we are like. The constants, variables, and methods that we define indicate how the new class differs from the one that we are extending.
We have done this all semester to create WindowControllers and ActiveObjects. For example, consider the header
public class Fall extends WindowController
from our falling leaves example. Fall is a WindowController. It has the same behaviors and properties as other WindowControllers, except for the things that we specify: 1) how it it draws the display (defined in the begin method) and 2) how it responds to mouse clicks (creating a tree from which leaves fall).
Here, we call Fall the subclass and WindowController the superclass.
Since Fall extends WindowController, Fall also has a canvas instance variable we can use, even though we did not declare it ourselves. The WindowController also provides the code that makes sure onMousePress() gets called when we expect. And since WindowController extends Controller, we know that Fall implicitly extends Controller.
So we can call methods getImage and getAudio because they are defined in Controller.
JApplet is a Java class. Since our Fall class extends JApplet (indirectly), we can also do everything that Applets can do. There are lots of methods in JApplet (and the classes it, in turn, extends), but the only one we have really been using is the getContentPane() method that allows us to add Swing components to the display.
Describing similar things |