Training Index
The StickFigure Bean with Properties
by John Zukowski, MageLang Institute
date here
[Help |
API Docs |
Short Course | Magercises]
This Magercise focuses on JavaBeans design patterns for properties. The primary task is to add a bound property to the StickFigure Bean. Secondary tasks include building, packaging, and loading the Bean into a Bean-aware tool for verification.
Magercise 3 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, within workingdir and (2) save the *.java skeleton files within stickfigure, that is, within workingdir/stickfigure.
- The next task is to add the bound property "sunburned" to the StickFigure Bean. You must add the isSunburned() and setSunburned() access methods, as well as a boolean variable, say, hasSunburn, which is manipulated by these two methods.
The "sunburned" logic is that if a StickFigure Bean instance is sunburned, the drawing operations should use Color.red as the foreground color. That is, the principal tasks of the setSunburned() method are:
- Set hasSunburn to true or false as specified by the argument
- Set the Bean instance's "foreground" property programmatically, for example:
setForeground(Color.red);
In addition, depending on your design, you will probably need to capture and record/retain the old, pre-sunburn value for the "foreground" property, so that upon a setSunburned(false) method call, you can restore the old value.
- 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, select StickFigure from the palette and create an instance on the worksheet. Verify that the "sunburned" property is present and works properly.
Where help exists, the task numbers above are linked to the step-by-step
help page.
Note that the "mood" property displays the integer value -1. The set of possible values includes -1, -2, and -3. These magic numbers are unacceptable for Beans designed to be used by other programmers; hence, in an upcoming Magercise, you can add a custom property editor that displays meaningful string values.
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:
- Magercise 4
- Short Course
- About This Short Course
Copyright © 1998-1999
MageLang Institute.
All Rights Reserved.
|
|