Various subpackages of java.awt allow you to manipulate images, sounds, and other media:
- java.awt.color color manipulation tools
- java.awt.datatransfer moving data between applications, such as with cut, copy, and paste
- java.awt.dnd drag-and-drop functionality
- java.awt.event various event listener and adapter classes for connecting events to your code
- java.awt.font font manipulation APIs
- java.awt.geom 2D geometry
- java.awt.im input method interfaces for localized input devices
- java.awt.image several interfaces and classes for reading and manipulating images
- java.awt.print printing APIs
25.2. java.applet Applets
Applets are a way to run code inside another applicationcommonly a web browser. Applets are the first
exposure many people have to the Java virtual machine and its uses. An applet is defined primarily by the
protocol that governs its lifetime and the methods by which it can query and manipulate its runtime
environment. The types in java.appletprimarily the Applet superclass itselfdefine this environment.
When an
The method init is one of four lifecycle methods defined for the applet in the Applet class. After init is
called, start is called, which tells the applet that it is active and should perform its function. If the browser
decides that the applet is no longer of interest to the user, for example, the user leaves the page the applet was
on, the applet's stop method is invoked to tell it to stop what it was doing. If the user returns to the applet's
page the browser may invoke start again to tell the applet to recommenceso the applet can cycle through a
stopstart sequence as the user presses the "Back" and "Forward" buttons (or their equivalents) to visit and
leave the page. When the browser decides that the applet is no longer of interest (perhaps because the user has
moved a number of pages away) the applet's destroy method is invoked to free up any resources used by
the applet. If the applet's page is now revisited the lifecycle will recommence with init being called again.
The browser ultimately defines the lifecycle of an applet and may choose to invoke destroy immediately
after stop when the user leaves the page. Whether or not an applet class is unloaded and reloaded between
visits to the applet is again a feature of the browser.
These lifecycle methods are typically overridden by applet classes. For example, if an applet uses a thread to
do its work, init would typically create the thread; start would invoke the thread's start method the
first time and ask it to continue execution on subsequent invocations; stop could ask the thread to pause to
prevent it from consuming resources while the page is not visible; and destroy could interrupt the thread
because the thread would no longer be needed.
An applet can get parameters from a tag to customize its behavior. It might get colors, fonts, or the
URL of an image to display.
Applets usually run in a highly constrained security environment to protect your computer and network from
unwelcome inspection or invasion by a hostile applet. This means that certain conveniences, such as a local
scratch disk, may not be available by default. You can grant permission to perform particular actions to
individual applets by specifying an appropriate security policy.