As we mentioned in the text, the lablets for this
chapter tie together nearly all of the Java language features and
programming topics that we have discussed throughout the book. These
programs make use of most of Java's statements and standard classes,
as well as arrays, packages, inheritance, exceptions, and threads,
all in the realistic context of creating graphical and animated buttons.
The resulting classes are written generally so that they can be used
directly in any future programs that you write. So, by completing
this last set of exercises you will have reached the point where you
can implement useful, re-usable, "industrial-strength" widgets of your
own devising (with a little help from us).
The new
material that is illustrated here, dealing primarily with Java's
multimedia classes, also represents an interesting closure because it
presents Java in its original intended context: as a language for
writing programs for the Worldwide Web. The relationship between Java
and HTML is, at long last, made explicit here, and the virtues of the
aforementioned language features become more obvious than ever.
![]() |
In this lab, you will: | ||
![]() |
View the two lablets for this chapter from within a single HTML page. |
||
![]() |
See how we can provide parameters to an applet using HTML, and how applets access and make use of parameters. |
||
![]() |
Experiment with the parts of
the lablets that use the |
||
![]() |
Extend both lablets to do more advanced image processing. |
GraphicButton
from Exercise 4.b above,
create an applet that produces a "locking button group"--that is, a
collection of locking graphic buttons displayed in a single panel, only
one of which can be "down" at any time.
GraphicButton
, and at least three
for an AnimatedButton
. Let's try to simplify things for
the users of our classes, as follows.
GraphicButton
so that it accepts a single
image as a parameter (you can use the value of the "pattern" parameter
to specify the file name for the image, and can get rid of the "numPix"
parameter). Then, have GraphicButton
use an image filter,
[pp. 532-535] to create a different
version of the image that will be displayed for the button's "down" state.
For "sculptural" buttons, like the images we've provided, an
InvertFilter
often works well.
AnimatedButton
so that it, too, requires
only a single image as its "pattern" parameter. It should, like the
revised GraphicButton
above, use a filter to produce the
image to be used for the button's "down" state. The "up" states for
the animated button should be produced be repositioning the button's
label. That is, the image for the animated button will not change
when the button is "up," but the position of the label will. So, an
animated button with a "label" value of "Hi!" might cycle through four
animated images as follows.FadeFilter
[Ex. 12, p. 566],
for example) for use when the button is disabled, and implement
an override of the function setEnabled()
so that a disabled
button shows up as faded and will not respond to any user actions.
![]() |
Spinner
object should have methods setValue()
and getValue()
that allow access to the displayed number. Implement a Spinner
class and make an applet containing a Spinner
object.