img
The Applet Class
T
his chapter examines the Applet class, which provides the foundation for applets.
The Applet class is contained in the java.applet package. Applet contains several
methods that give you detailed control over the execution of your applet. In addition,
java.applet also defines three interfaces: AppletContext, AudioClip, and AppletStub.
Two Types of Applets
It is important to state at the outset that there are two varieties of applets. The first are those
based directly on the Applet class described in this chapter. These applets use the Abstract
Window Toolkit (AWT) to provide the graphic user interface (or use no GUI at all). This
style of applet has been available since Java was first created.
The second type of applets are those based on the Swing class JApplet. Swing applets use
the Swing classes to provide the GUI. Swing offers a richer and often easier-to-use user interface
than does the AWT. Thus, Swing-based applets are now the most popular. However, traditional
AWT-based applets are still used, especially when only a very simple user interface is required.
Thus, both AWT- and Swing-based applets are valid.
Because JApplet inherits Applet, all the features of Applet are also available in JApplet,
and most of the information in this chapter applies to both types of applets. Therefore, even if
you are interested in only Swing applets, the information in this chapter is still relevant and
necessary. Understand, however, that when creating Swing-based applets, some additional
constraints apply and these are described later in this topic, when Swing is covered.
NOTE  For information on building applets when using Swing, see Chapter 29.
OTE
Applet Basics
Chapter 13 introduced the general form of an applet and the steps necessary to compile and
run one. Let's begin by reviewing this information.
All applets are subclasses (either directly or indirectly) of Applet. Applets are not
stand-alone programs. Instead, they run within either a web browser or an applet viewer.
The illustrations shown in this chapter were created with the standard applet viewer, called
appletviewer, provided by the JDK. But you can use any applet viewer or browser you like.
Execution of an applet does not begin at main( ). Actually, few applets even have main( )
methods. Instead, execution of an applet is started and controlled with an entirely different
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home