Training Index
The StickFigure Bean with a Custom Property Editor
By John Zukowski, MageLang Institute
[Help |
API Docs |
Short Course | Magercises]
This Magercise focuses on the design and implementation of a custom property editor, as well as its specification within the bean-info class.
Magercise 6 Prerequisites
Skeleton Code
Tasks
- The first step is to create a working directory somewhere on your filesystem, hereafter referred to as workingdir.
- Next, create the directory stickfigure (all lowercase characters) directly under workingdir.
- 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.
- 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:
public void setValue(Object o) { }
public Object getValue() { }
public String getAsText() { }
public void setAsText(String s)
throws IllegalArgumentException { }
public String[] getTags() { }
|
- 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.
- Compile all Java source files, *.java, from workingdir by including the stickfigure directory in the path specification.
- Build StickFigure.jar from workingdir by executing the file MakeStickFigureJar.bat (Windows) or MakeStickFigureJar.sh (UNIX).
- Next, load the StickFigure Bean into the BeanBox (or a comparable tool) using "LoadJar..." from the BeanBox "File" menu.
- 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.
Where help exists, the task numbers above are linked to the step-by-step
help page.
Solution Source
Demonstration
After loading the StickFigure Bean, it should appear in the palette, from where it can be selected and instantiated on the worksheet:
Notice the restricted number of properties displayed in the property sheet, as well as the custom "mood" property editor.
- Magercise 7
- Short Course
- About This Short Course
Copyright © 1998-1999
MageLang Institute.
All Rights Reserved.
|
|