Java Beans  «Prev  Next»
Lesson 5Using the BeanBox at design time
ObjectiveUse BeanBox test container to customize example Beans

Customize Design Time Bean

Let us insert a Bean into the BeanBox to get familiar with how the BeanBox works in design time mode. Click the link below to insert and customize a Bean in design time mode. The JavaBeans API makes it possible to write component software in the Java programming language.
Components are self-contained, reusable software units that can be visually composed into composite components, applets, applications, and servlets using visual application builder tools. JavaBean components are known as Beans.

Customizing Java Bean at Design Time using BeanBox

Objective: Customize the BlueButton Bean at design time with the Bean Box
  1. Launch the BeanBox by executing the run.bat file in the beanbox directory beneath the main Bdk directory.
    (Remember: the JDK's bin directory must be included in your system path in order for the BeanBox to work correctly.)
  2. In the ToolBox window, click on the text BlueButton. Note that the mouse pointer has changed to a crosshair.
  3. Move the crosshair over the BeanBox window.
  4. Click in the BeanBox window to insert the bean.


The BlueButton Bean now appears in the BeanBox window. You can now customize the bean.
  1. Click the blue box in the Properties window. The ColorEditor appears.
  2. Click the arrow to the right of the word blue.
    A drop-down menu appears.
  3. Click on the orange; menu item.
    The BlueButton bean is now orange.
  4. Close the ColorEditor window.
  5. In the Properties window, click in the label field.
    Delete the word press.
  6. In the label field, type Push me!.

The BeanBox should now contain an orange button with a Push me! label.

 The BlueButton Bean in the Toolbox
1)The BlueButton Bean in the Toolbox

 The BlueButton Bean added to the BeanBox
2)The BlueButton Bean added to the BeanBox

 The BlueButton Bean's properties
3)The BlueButton Bean's properties

 The color property editor for the background color
4)The color property editor for the background color

 Selecting the color orange
5)Selecting the color orange

 6
6)6

 7
7)7

 8
8)8

 9
9)9




Javabeans Components

Components expose their features (for example, public methods and events) to builder tools for visual manipulation. A Bean's features are exposed because feature names adhere to specific design patterns. A "JavaBeans-enabled" builder tool can then examine the Bean's patterns, discern its features, and expose those features for visual manipulation. A builder tool maintains Beans in a palette or toolbox. You can
  1. select a Bean from the toolbox,
  2. drop it into a form,
  3. modify its appearance and behavior,
  4. define its interaction with other Beans, and
  5. compose it and other Beans into an applet, application, or new Bean.
All this can be done without writing a line of code.

Persistence

Generally, all components have state. The thermostat component has state that represents the comfort temperature. If the thermostat were a software component of a computer-based heating control system, we would want the value of the comfort temperature to be stored on a non-volatile storage medium (such as the hard disk). In this manner, if we shut down the application and brought it back up again, the thermostat control would still be set to 73 degrees. The visual representation and position of the thermostat relative to other components in the application would be restored as well. Components must be able to participate in their container's persistence mechanism so that all components in the application can provide application-wide persistence in a uniform way. If every component were to implement its own method of persistence, it would be impossible for an application container to use components in a general way. This would not be an issue if reuse were not the goal. If we were building a monolithic temperature control system [HAL 9000] we might create an application-specific mechanism for storing state. But we want to build the thermostat component so that it can be used again in another application, so we have to use a standard mechanism for persistence.
In the next lesson, the BlueButtonBean will be tested in runtime mode.