ptg7068951
WHAT YOU’LL LEARN IN
THIS HOUR:
.Stopping and starting an
applet
.Putting an applet on a web
page
.Customizing an applet with
parameters on a web page
.Displaying web pages in an
application
Java has become successful as a general-purpose language that runs on
many distinct platforms, including cell phones, web servers, and Internet
appliances. When the language was introduced in the mid-1990s, it was
the first programming language that could run inside a web browser.
Appletsare Java programs designed to run as part of a web page. When a
Java applet is encountered on a page, it is downloaded to the user’s com-
puter and begins running.
Programming applets is different than creating applications with the lan-
guage. Because applets must be downloaded from a page each time they
are run, they’re smaller than most applications to reduce download time.
Also, because applets run on the computer of the person using the applet,
they have security restrictions in place to prevent malicious or damaging
code from being run.
Standard Applet Methods
The first step in the creation of an applet is to make it a subclass of
JApplet, a class in the Swing package javax.swing. An applet is treated as
a visual window inside a web page, so JAppletis part of Swing alongside
buttons, scrollbars, and other components of a program’s user interface.
The applets you write inherit all the behavior and attributes they need to
be run as part of a web page. Before you begin writing any other state-
ments in your applets, they are able to interact with a web browser, load
and unload themselves, redraw their windows in response to changes in
the browser window, and handle other necessary tasks.
HOUR 17
Creating Interactive Web
Programs