Just one:
public void paint ( Graphics gr )
(However, the class inherits many more methods
from class JApplet
.)
JApplet
Class
The definition of JApplet
provides a framework
for building an applet.
By itself, the class JApplet
does little that is visible in
the Web browser.
(It does a great many things behind the scenes, however.)
To build upon this framework, you
import
javax.swing.JApplet
and
extend
the JApplet
class.
// X -- notice the 'x' in javax import javax.swing.JApplet; import java.awt.*; public class Poem extends JApplet { public void paint ( Graphics gr ) { setBackground( Color.white ); gr.drawString("Loveliest of trees, the cherry now", 25, 30); gr.drawString("Is hung with bloom along the bough,", 25, 50); gr.drawString("And stands about the woodland ride", 25, 70 ); gr.drawString("Wearing white for Eastertide." ,25, 90); gr.drawString("--- A. E. Housman" ,50, 130); } }
When you extend a class, you are making a new class by
building upon a base class.
This example defines a new class called Poem
.
The new class has everything in it that the class JApplet
has.
(This is called inheritance.
Inheritance is discussed at greater length in chapter 50.)
The class JApplet
has a paint()
method,
but that method does little.
Objects of class
Poem
have their own
paint()
method because the definition in Poem.java
overrides the one in JApplet
.
The Web browser calls the paint()
method when it needs to "paint"
the section of the monitor screen devoted to an applet.
Each applet that you write
has its own paint()
method.
Say that the Web browser has just called the paint()
method.
Its first statement is:
setBackground( Color.white );
What do you suppose that this does?