public void paint ( Graphics gr )
The parameter is a reference to an object of type Graphics
.
The definition of Applet
which the program imports provides a framework
for building your applet.
By itself, the class Applet
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 extend the Applet class:
import java.applet.Applet; import java.awt.*; public class AEHousman extends Applet { public void paint ( Graphics gr ) { setBackground( Color.pink ); 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.
In this example, we are defining a new class called AEHousman
.
The new class will have everything in it that the class Applet
has.
(This is called inheritance.)
The class Applet
has a paint()
method, but it does little.
In our definition of AEHousman
,
the definition of paint()
replaces the one in Applet
.
The web browser calls the paint()
method when it needs to "paint"
the section of the monitor screen devoted to an applet.
The applets that you write will
have their own paint()
method.