Download the JDK
Search the Tutorials
Hide the TOC
Trail: Deployment
Lesson: Applets
Section: Getting Started with Applets
Applets
Getting Started with Applets
Importing Classes and Packages for Applets
Defining an Applet Subclass
The Life Cycle of an Applet
Methods for Milestones
Methods for Drawing and Event Handling
Methods for Adding UI Components
What Applets Can and Can't Do
Taking Advantage of the Applet API
Finding and Loading Data Files
Displaying Short Status Strings
Displaying Documents in the Browser
Sending Messages to Other Applets
Playing Sounds
Defining and Using Applet Parameters
Deciding Which Parameters to Support
Writing the Code to Support Parameters
Giving Information about Parameters
Using the APPLET Tag
Practical Considerations When Writing Applets
Security Restrictions
Creating a User Interface
Creating a GUI
Displaying Diagnostics to the Standard Output and Error Streams
Getting System Properties
Threads in Applets
Threads in Applets: Examples
Working with a Server-Side Application
A Simple Network Client Applet
Using a Server to Work Around Security Restrictions
Finishing an Applet
Before You Ship that Applet
The Perfectly Finished Applet
Deploying Applets
General Deployment Considerations
Using the applet Tag
Using the object Tag
Using the embed Tag
Deploying Applets in a Mixed-Browser Environment
Solving Common Applet Problems
Questions and Exercises
Home Page > Deployment > Applets
Defining an Applet Subclass

> The first bold line of the following listing begins a block that defines the `HelloWorld` class.

> >     import javax.swing.JApplet;
> >     import java.awt.Graphics;

> >     public class HelloWorld extends JApplet {
> >         public void paint(Graphics g) {
> >     	g.drawRect(0, 0,
> >     		   getSize().width - 1,
> >     		   getSize().height - 1);
> >             g.drawString("Hello world!", 5, 15);
> >         }
> >     }

> Applets inherit a great deal of functionality from the `Applet` or `JApplet` class, including abilities to communicate with the browser and present a graphical user interface (GUI) to the user.

> An applet which will be using GUI components from Swing (Java's GUI toolkit) should extend the `javax.swing.JApplet` base class, which provides the best integration with Swing's GUI facilities.

> `JApplet` provides the same "RootPane" top-level component structure as Swing's `JFrame` and `JDialog` components, whereas `Applet` provides just a simple panel. See How to Use Root Panesfor more details on how to utilize this feature.

> An applet may extend `java.applet.Applet` when it makes no use of Swing's GUI components. This may be the case if the applet does all its own rendering using the Java graphics libraries (such as with graphing or gaming) and/or uses only AWT components.

Previous page: Importing Classes and Packages for Applets
Next page: The Life Cycle of an Applet