The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: JavaBeans(TM)
Lesson: Using the BeanBox

Starting and Using the BeanBox

This section gives you a brief, introductory look at the BeanBox and it's basic operation. The beans/beanbox directory contains Windows (run.bat) and Unix (run.sh) scripts that start the BeanBox. You can use these commands to start the BeanBox, or use a make utility:

Platform Command
Unix gmake run
Windows nmake run

See the BDK files beans/doc/makefiles.html and beans/doc/gnu.txt for information about getting copies of gnumake and nmake.

When started, the BeanBox displays three windows: The ToolBox, the BeanBox window, and the Properties sheet.


This figure has been reduced to fit on the page.
Click the image to view it at its natural size.

Here are brief descriptions of each window.

Adding a Bean to the ToolBox

When the BeanBox is started, it automatically loads the ToolBox with all the Beans it finds within the JAR files contained in the beans/jars directory. Move your JAR files into that directory to have them automatically loaded at BeanBox startup. You can load Beans from JAR files located elsewhere by using the File|LoadJar... BeanBox menu item.

Dropping a Bean on the BeanBox

Clicking on a Bean name within the ToolBox chooses that Bean for placement within the BeanBox. To drop a JellyBean instance onto the BeanBox

  1. Click on the word JellyBean in the ToolBox. The cursor will change to a crosshair when flying over the BeanBox windows.
  2. Click within the BeanBox. The JellyBean instance will appear, and will be selected.

Note the change in the Properties sheet when you put the JellyBean in the BeanBox. Before you placed the JellyBean in the BeanBox, the BeanBox's properties were displayed. After placing the JellyBean in the BeanBox, the JellyBean properties are displayed. If you missed the change, click within the BeanBox, away from the JellyBean. This will select the BeanBox rather than the JellyBean. The Properties sheet will then display the BeanBox's properties.

After dropping a JellyBean instance on the BeanBox, the Properties sheet displays the JellyBean properties: color, foreground, priceInCents, background, and font.

Editing Bean Properties

The Properties sheet displays each property's name and its current value. Values are displayed in an editable text field (strings and numbers), a choice menu (booleans), or as painted values (colors and fonts). Each property has an associated property editor. Clicking on a property within the Properties sheet activates the property's editor. Properties displayed in text fields or choice menus are edited within the Properties sheet. Because editing their values requires a more sophisticated user interface, Color and Font property types use a custom property editor. When you click on a color or font property a separate panel will pop up to do the editing. Try clicking on each of the JellyBean properties.

Saving and Restoring Beans

You can save the state of a Bean that your are customizing, and restore the Bean and its saved state at a later time. The BeanBox uses Java Object Serialization to save and restore Beans and their state. The following steps demonstrate how to save and restore a Bean:

  1. Drop a JellyBean on the BeanBox.
  2. Change the color property to anything you want.
  3. Select the File|Save menu item. A file browser will pop up; use it to save the Bean to a file.
  4. Select the File|Clear menu item.
  5. Select the File|Load menu item. The file browser will again pop up; use it to retrieve the serialized Bean. The JellyBean will be the color you chose.


Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.