180 likes | 313 Views
JavaBeans Workshop. Working with BeanBox Example1: The Juggler Starting and Stoping juggling with two buttons Example2: A ThermoBean Raising and lowering a temperature with two buttons. Building a simple Java bean ColorPanelBean. Activating the BeanBox. Go to directory “c:bdkbeanbox”.
E N D
JavaBeans Workshop • Working with BeanBox • Example1: The Juggler • Starting and Stoping juggling with two buttons • Example2: A ThermoBean • Raising and lowering a temperature with two buttons. • Building a simple Java bean • ColorPanelBean
Activating the BeanBox • Go to directory “c:\bdk\beanbox”. • Issue the command “run.bat”.
Creating a Juggler • Select item Juggler from menu ToolBox. • Place the Juggler on the BeanBox.
Adding Control Buttons • Place two buttons on the BeanBox. • Specify the properties of the buttons with a Property Sheet.
Example 1: The Juggler • Select event to be performed on Start button
Example 1: The Juggler • Choose event target --> Juggler
Example 1: The Juggler • Choose target method --> startJuggler
Example 1: The Juggler • How to stop the Juggler • Select event to be performed on Stop button • Choose event target --> Juggler • Choose target method --> stopJuggler • Juggler Example is ready to be tested!
Example 2: The ThermoBean • Import customized bean --> ThermoBean • Select LoadJar and the choose Thermo.jar in \workshop
Example 2: The ThermoBean • New bean are already to be used!
Example 2: The ThermoBean • Raise Temperature • Select event to be performed on Raise button • Choose event target --> Thermo • Choose target method --> stopJuggler • Lower Temperature • Select event to be performed on Lower button • Choose event target --> Thermo • Choose target method --> stopJuggler
Creating and Testing the Simplest Bean • Create a SimplestBean.java source file • Create a Manifest file Name: SimplestBean.class Java-Bean: True • Build SimplestBean.class • Pack them to .jar file • jar -cvfm <SimpleBean.jar> <Manifest file> <SimplestBean.class> • It’s ready to import to BeanBox or Other Tools
What are we going to create? • A simple bean that change Red Value through a scrollbar names PanelBean.java
ScrollbarBean: Bound Properties Scrollbar • Simple scrollbar extends from java.awt.Scrollbar • Add some methods to support Bound Properties in Java Beans • Use event PropertyChange to notify other beans
Hint: Creating PanelBean.java • PanelBean must extend from java.awt.Panel • Support getter/setter its property --> redValue • Color of the panel can be set using setBackground(new Color(Red, Green, Blue)); • Use Bound Properties: hence must implement java.beans.PropertyChangeListener • Method public void propertyChange(PropertyChangeEvent e) must be implemented
More Information • “Core JAVA Volume II-Advanced Features”, Sun Microsystems Press. • http://java.sun.com