The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Getting Started
Lesson: The Anatomy of an Applet

Defining an Applet Subclass

The first bold line of the following listing begins a block that defines the HelloWorld 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(in the Getting Started trail).

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 Applets(in the Getting Started trail) lesson.

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 the Applet subclass originated from.


Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2002 Sun Microsystems, Inc. All rights reserved.