Page 220 - Introduction to Programming with Java: A Problem Solving Approach
P. 220

                186 Chapter 5 Using Pre-Built Methods
   Apago PDF Enhancer
Figure 5.16 Output produced by program in Figure 5.17
The code in Figure 5.17 is very skimpy. For example, it does not include a definition of the getImage method. So how can it call that method? As you’ll discover in Chapter 12, Java allows any class you define to borrow the methods of another class that’s already been defined. In particular, the GraphicsDemo class defined in Figure 5.17 borrows the getImage method from the already-defined Java API Applet class.
It does this by appending the clause extends
know where to find the Applet class, so the program must import it. It also imports the java.awt package to provide access to the Graphics, Image, and Color classes used by statements in the paint method.
Applet to its class heading. Of course, the compiler must




























































































   218   219   220   221   222