Java Reference
In-Depth Information
The
presentNation(index)
method (lines 63-68) presents a nation with the specified
index. It sets a new image in the label (line 64), synchronizes with the combo box by setting
the selected index (line 65), and plays the new audio (line 67).
The applet's
start
and
stop
methods are overridden to resume and suspend the audio
(lines 70-78).
18.27
✓
✓
Which code sets the initial image icon? Which code plays the initial audio clip?
Check
18.28
What does the program do when the
Suspend
button is clicked? What does the pro-
gram do when the
Resume
button is clicked?
Point
K
EY
T
ERMS
applet 673
applet container
HTML 673
signed applet
677
676
archive
674
tag
673
C
HAPTER
S
UMMARY
1.
JApplet
is a subclass of
Applet
. It is used for developing Java applets with Swing
components.
2.
The applet class file must be specified, using the
<applet>
tag
in an
HTML file
to
tell the Web browser where to find the applet. The applet can accept string parameters
from HTML using the
<param>
tag.
3.
The
applet container
controls and executes applets through the
init
,
start
,
stop
,
and
destroy
methods in the
Applet
class.
4.
When an applet is loaded, the applet container creates an instance of it by invoking its
no-arg constructor. The
init
method is invoked after the applet is created. The
start
method is invoked after the
init
method. It is also called whenever the applet
becomes active again after the page containing the applet is revisited. The
stop
method is invoked when the applet becomes inactive.
5.
The
destroy
method is invoked when the browser exits normally to inform the applet
that it is no longer needed and should release any resources it has allocated. The
stop
method is always called before the
destroy
method.
6.
Applications and applets are very similar. An applet can easily be converted into an
application, and vice versa. Moreover, an applet can be written with a
main
method to
run standalone.
7.
You can pass arguments to an applet using the
param
attribute in the applet's tag in
HTML. To retrieve the value of the parameter, invoke the
getParameter(paramName)
method.
8.
The
Applet
's
getParameter
method can be invoked only after an instance of the
applet is created. Therefore, this method cannot be invoked in the constructor of the
applet class. You should invoke this method from the
init
method.
9.
You learned how to incorporate images and audio in Java applications and applets. To
load audio and images for Java applications and applets, you have to create a
URL
object
for the audio and image file. The resource files must be stored in the class directory.