Exercise 15-1. Chapters
10,
12, and
13 contain examples of Swing components that
allow the user to scribble with the mouse. Choose one of these
classes, rename it to ScribbleBean, and package it
in a JAR file (along with any other example classes it may require).
Now install it in a beanbox application of your choice, to
demonstrate that it works. Give your bean an erase(
) method that erases the scribbles, and use the beanbox to
create a push button of some sort that invokes this method.
Exercise 15-2. Modify your ScribbleBean bean so that it has color
and line-width properties that specify the color and width of the
lines used for the scribbles. Repackage the bean and test the
properties in a beanbox.
Exercise 15-3. An application that uses a ScribbleBean bean might
want to be notified each time the user completes a single
"stroke" of the scribble (i.e.,
each time the user clicks, drags, and then releases the mouse). For
example, an application might make an off-screen copy of the scribble
after each stroke, so that it could implement an undo facility. In
order to provide this kind of notification, modify your
ScribbleBean bean to support a
"stroke" event. Define a simple
StrokeEvent class and
StrokeListener interface. Modify the
ScribbleBean bean so that it allows registration
and removal of StrokeListener objects, and so that
it notifies all registered listeners each time a stroke of the
scribble is complete. Regenerate the bean's JAR file
so that it includes the StrokeEvent and
StrokeListener class files.
Exercise 15-4. Define a BeanInfo subclass for the
ScribbleBean bean. This class should provide
information about the erase( ) method, the color
and width properties, and the stroke event defined by the bean. The
BeanInfo class should use the
FeatureDescriptor.setShortDescription( ) method to
provide simple, descriptive strings for the bean itself and its
method, properties, and event.
Exercise 15-5. Modify the Bean class of Example 15-10 so that it can return a customizer object for
the bean it represents, if a customizer class exists. Modify the
ShowBean class of Example 11-30 to
include a Customize... button in its
File menu that displays the
customizer. This menu item should be disabled when no customizer
exists. Test your changes with the YesNoPanel bean
and its customizer class.