![]() ![]() ![]() |
Start of Tutorial > Start of Trail > Start of Lesson | Search |
The first bold line of the following listing begins a block that defines theHelloWorld
class.import java.applet.Applet; import java.awt.Graphics; public class HelloWorld extends Applet { public void paint(Graphics g) { g.drawString("Hello world!", 50, 25); } }The
extends
keyword indicates that HelloWorld is a subclass of the class whose name follows:Applet
. If the term subclass means nothing to you, you'll learn about it soon in Object-Oriented Programming Concepts.
From the
Applet
class, applets inherit a great deal of functionality. Perhaps most important is the ability to respond to browser requests. For example, when a Java-capable browser loads a page containing an applet, the browser sends a request to the applet, telling the applet to initialize itself and start executing. You'll learn more about what the Applet class provides in the Overview of Appletslesson.
An applet isn't restricted to defining just one class. Besides the necessary
Applet
subclass, an applet can define additional custom classes. When the applet attempts to use a class, the application that's executing the applet first looks on the local host for the class. If the class isn't available locally, it's loaded from the location that theApplet
subclass originated from.
![]() ![]() ![]() |
Start of Tutorial > Start of Trail > Start of Lesson | Search |