Experiment 9
Experiment 9
JavaBeans are classes that encapsulate many objects into a single object (the bean). It is a Java class
that should follow the following conventions:
// Properties
private static final Color COLOR_OFF = Color.BLACK;
private Color color = Color.ORANGE; // property with a default value
public Color getColor() { return color; } // getter
public void setColor(Color color) { this.color = color; } // setter
> cd $CLASS_BASEDIR
> jar cmfv manifest.Bulb $JAR_BASEDIR/lightbulb.jar elect\LightBulb.class
2. From the "Beanbox" window, choose "File" ⇒ "LoadJar" ⇒ Chose "lightbulb.jar". You shall
see LightBulb appears at the bottom of the "ToolBox" window.
3. Select LightBulb from the "ToolBox" window, and place it into the "Beanbox". Observe that
the "Property" window shows the two properties defined in this bean: color and on. Try
changing these properties and observe the result. The "Property" window also shows the
properties inherited from the superclasses.
4. Select "OurButton" bean (a demo bean provided by BDK) from "Toolbox" and place it inside
the "Beanbox". In the "Property" window, change the "label" from "press" to "toggle".
7. Focus on LightBulb, choose "Edit" from menu ⇒ "Events" ⇒ "mouse" ⇒ "mouseClicked" and
place it back to LightBulb. In the "EventTargetDialog", select method toggle() as the event
handler.
8. Click the LightBulb and observe the effect.