Java Reference
In-Depth Information
Example 14−9: YesNoPanelCustomizer.java (continued)
}
}
Exercises
14-1. Chapters 10, 12, and 13 contain examples of AWT and 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 applica-
tion 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.
14-2. Modify your ScribbleBean bean so that it has color and line-width proper-
ties that specify the color and width of the lines used for the scribbles.
Repackage the bean and test the properties in a beanbox.
14-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 appli-
cation 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 StrokeLis-
tener 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.
14-4. Define a BeanInfo subclass for the ScribbleBean bean. This class should
provide information about the erase() method, the color and width proper-
ties, and the stroke event defined by the bean. The BeanInfo class should
use the FeatureDescriptor.setShortDescription() method to provide sim-
ple descriptive strings for the bean itself and its method, properties, and
event.
Search WWH ::




Custom Search