|
By John Zukowski, MageLang Institute [Magercise 6 | API Docs | Short Course | Magercises] Help is available for each task. The first step is to create a working directory somewhere on your filesystem, hereafter referred to as workingdir. To avoid confusion, create a new directory instead of using an existing directory that has existing/other files. Next, create the directory stickfigure (all lowercase characters) directly under workingdir. To avoid subsequent confusion, create and verify that the directory name contains all lowercase characters. The directory stickfigure will house the StickFigure-related classes, which belong to the stickfigure package. The package and directory names must match exactly, and in some Bean-aware environments, they must be lowercase. Next, (1) save all the skeleton files, except the *.java files and GIF file, within workingdir and (2) save the *.java skeleton files and GIF file within stickfigure, that is, within workingdir/stickfigure. Actually, the GIF file could be anywhere, but it is customary to locate it within the package directory, in this case, stickfigure. The next, and primary, task is to design and implement a custom "mood" property editor for the StickFigure Bean, MoodEditor. This class must extend PropertyEditorSupport and provide "mood" property-specific definitions for the following methods:
Use the Hire Bean's DepartmentEditor as a model. MoodEditor should be in the stickfigure package; hence, it can use the int and String constants representing mood states as defined in StickFigure.java. The next task is to augment the bean-info class, StickFigureBeanInfo. Add a getPropertyDescriptors() method that returns an array of two PropertyDescriptor instances for the "mood" and "sunburned" properties, respectively. Use HireBeanInfo as a model. Don't forget to set the property editor using setPropertyEditorClass(). Compile all Java source files, *.java, from workingdir by including the stickfigure directory in the path specification. From a command window type (excluding the prompt): C:\workingdir>javac stickfigure\*.java [DOS] or /workingdir>javac stickfigure/*.java [UNIX] An alternative approach, if you prefer graphical tools, is to build the stickfigure package within your Java development environment. Verify that StickFigure.class, StickFigureEvent.class, and StickFigureListener.class exist within the stickfigure directory by typing (excluding the prompt):
Build StickFigure.jar from workingdir by executing the file MakeStickFigureJar.bat (Windows) or MakeStickFigureJar.sh (UNIX). From a command window type (excluding the prompt):
Next, load the StickFigure Bean into the BeanBox (or a comparable tool) using "LoadJar..." from the BeanBox "File" menu. Start up the BeanBox, select "LoadJar..." from the BeanBox "File" menu, and then navigate to your workingdir and open/load StickFigure.jar. Lastly, note the property editor for StickFigure Bean. The "mood" property should appear in the property sheet as a drop-down list. Verify that selecting different values from the list changes the image so that it displays a smile, frown, etc. Return to Magercise 6 Copyright © 1998-1999 MageLang Institute. All Rights Reserved. | ||||||||||||||||
|
| ||||||||||||