StickFigure
Bean with BeanInfo SupportThis Magercise focuses on the mechanics of providing a simple bean-info class. The bean-info class will be modified in upcoming Magercises.
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 specify an icon for the StickFigure Bean. To do this, you must provide a bean-info class. In this case, start with the skeleton class definition in StickFigureBeanInfo.java. Implement a getIcon() method; see the JDK documentation, in particular, the BeanInfo interface and the SimpleBeanInfo class.
Compile all JavaTM 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 icon for the StickFigure Bean. In upcoming Magercises, the bean-info class will specify a custom property editor for the "mood" property, as well as a customizer class for the StickFigure Bean.
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. The meaningless magic numbers, of -1, -2, and -3, 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.
After loading the StickFigure Bean, it should appear in the palette, from where it can be selected and instantiated on the worksheet:
Notice the icon.