Java Reference
In-Depth Information
500), Current Time (e.g., 15:54), the index from the previous day (e.g.,
919.01), and Change (e.g., 4.54). Use at least five indexes, such as Dow Jones,
S&P 500, NASDAQ, NIKKEI, and Gold & Silver Index. Display positive
changes in green and negative changes in red. The indexes move from right to
left in the applet's viewing area. The applet freezes the ticker when the mouse
button is pressed; it moves again when the mouse button is released.
**18.17
(
Racing cars
) Write an applet that simulates four cars racing, as shown in
Figure 18.24a. You can set the speed for each car, with maximum 100.
(b)
(a)
F
IGURE
18.24
(a) You can set the speed for each car. (b) This applet shows each country's
flag, name, and description, one after another, and reads the description that is currently
shown.
**18.18
(
Show national flags
) Write an applet that introduces national flags, one after
the other, by presenting each one's photo, name, and description (see Figure
18.24b) along with audio that reads the description. Suppose your applet dis-
plays the flags of eight countries. Assume that the photo image files, named
flag0.gif
,
flag1.gif
, and so on, up to
flag7.gif
, are stored in a subdirectory
named
image
in the applet's directory. The length of each audio is less than 10
seconds. Assume that the name and description of each country's flag are
passed from the HTML using the parameters
name0
,
name1
, . . . ,
name7
, and
description0
,
description1
, . . . , and
description7
. Pass the number
of countries as an HTML parameter using
numberOfCountries
. Here is an
example:
<
param name
=
"numberOfCountries"
value
=
8
>
<
param name
=
"name0"
value
=
"Canada"
>
<
param name
=
"description0"
value
=
"The Canadian ... "
>
Hint
Use the
DescriptionPanel
class to display the image, name, and the
text. The
DescriptionPanel
class was introduced in Listing 17.2.
***18.19
(
Bouncing balls
) The example in Section 18.8 simulates a bouncing ball.
Extend the example to allow multiple balls, as shown in Figure 18.25a. You
can use the or button to increase or decrease the number of the balls,
and use the
Suspend
and
Resume
buttons to freeze the balls or resume bounc-
ing. For each ball, assign a random color.
+
1
-
1