The JApplet Class
A JApplet is a Swing JPanel with a mission. It is a GUI container
that has some extra structure to allow it to be used in the “alien”
environment of a web browser. Applets also have a lifecycle that lets them
act more like an application than a static component. Although applets
tend to be relatively simple, there’s no inherent restriction on their
complexity other than the issues of downloading and caching their content.
Historically, applets have tended to be small “widgets.”
The javax.swing.JApplet class
defines the core functionality of an applet. (java.awt.Applet is the
older, AWT-based form.)
Structurally, an applet is a wrapper for your Java code. In contrast
to a standalone graphical Java application, which starts up from a
main() method and creates a GUI, an
applet itself is a component that expects to be dropped into someone
else’s GUI. Thus, an applet can’t run by itself; it runs in the context of
a web browser or a special applet-viewer program (which we’ll talk about
later). Instead of having your application create a JFrame to hold your GUI, you stuff your
application inside a JApplet (which
itself extends Container) and let the
browser add your applet to the page.
Applets are placed on web pages with the <applet> HTML tag,
which we’ll cover later in this chapter. At its simplest, you just specify
the name of the applet class and a size in pixels for the applet:
<appletcode="AnalogClock"width="100"height="100"></applet>
Pragmatically, an applet is ...