The BeanBox
Home ] Up ] What are JavaBeans? ] The Bean Development Kit ] [ The BeanBox ] JavaBean Properties ] Simple and Indexed Properties ] Bound Properties ] Constrained Properties ] Bean Deployment ] Introspection ] Property Editors ] Customizers ] Bean Persistence ] New JavaBean Features ]

 

 

Once you've downloaded the BDK and unzipped it, you can try running the BeanBox tool. The BeanBox is a simple "IDE" for manipulating JavaBeans, and constructing apps from them.

In the subdirectory beanbox, you will find two files:

  • run.bat -- runs the BeanBox on MS Windows systems
  • run.sh -- runs the BeanBox on Unix (Solaris) systems

Invoke the appropriate one to run the BeanBox.

The BeanBox Windows

When it starts, you will see three (four in BDK 1.1) windows appear:

The ToolBox Window

The BeanBox Window

The Properties Window

The Method Tracer Window

The ToolBox Window

The BeanBox Window

The Properties Window

The Method Tracer Window

The ToolBox Window

The ToolBox window shows a list of the beans available for use by the BeanBox. To use one of these beans, you click on the bean, and drop it into the BeanBox window.

The BeanBox Window

The BeanBox window is where you visually place beans, and "connect them together", by defining how they interact with other beans. The BeanBox is actually an instance of the BeanBox bean -- you can see its properties displayed above.

You select a bean in the BeanBox window simply by clicking on the bean. The selected bean is depicted by a hatched border surrounding it. The Properties window shows the properties for the selected bean.

The Properties Window

The Properties window shows the properties for the bean currently selected in the BeanBox window.

The Method Tracer Window (new in BDK 1.1)

In BDK 1.1, the BeanBox includes some example BeanContext services, one of which is a service for providing simple method tracing and debug statement logging.  By writing beans in a specific way, you can incorporate simplistic debugging into your bean.  Note that this may not work properly on all VMs.  The logic in the trace method depends upon formatting of the message associated with an exception and this is not standardized.  It is simply intended to demonstrate the registration, request and utilization of a BeanContext service.

Adding a Bean to the ToolBox

When the BeanBox starts, it automatically loads the ToolBox with all the beans it finds within the JAR files located in the jars directory. If you have a set of beans, place them into one or more JAR files, and copy those JAR files into the jars subdirectory.

You can also load beans into the BeanBox by using the File->LoadJar ... menu item, and choosing the appropriate JAR file using a file dialog.

Dropping a Bean into the BeanBox

You can drop a bean into the BeanBox window as follows:

  1. Click on a bean within the ToolBox window. This changes the mouse cursor into a crosshair.
  2. Click within the BeanBox window. This drops an instance of the bean into the BeanBox at that position.

When you do this, the bean instance is selected (as shown by the hatched border), and the Properties window shows the bean's properties.

Editing Bean Properties

The Properties window displays a selected bean's properties. Each property shows:

  • The property name
  • The property value -- the value may be of various forms: text, color, font, etc.

A property value may be changed by clicking on the value of that property in the Property window. This activates the property's Property Editor. (If the form of the property value is text or choice, then the value is edited directly in the Property window.)

Saving and Restoring Beans

If you are working on a bean in the BeanBox, you can save its state and then later restore that bean's state (even from within a different BeanBox session). The BeanBox uses Java Object Serialization to save and restore the state of a bean (Note that this means that if a bean is not serializable, either directly, or via fields that it contains, then a save operation will fail.)

Saving a Bean's State

To save a bean's state from within the BeanBox:

  1. Select the [edited] bean in the BeanBox window
  2. Use the File->Save menu item to cause the bean to be serialized to a specified file.

Restoring a Bean's State

To restore a bean's state from within the BeanBox:

  • Use the File->Load menu item to cause the bean to be serialized in from a previously saved bean file. The bean will be restored to its position in the BeanBox window.

Building a Simple Application Using the BeanBox

The standard demo of how to use the BeanBox to build a simple application is to use the "Juggler" Bean, which depicts Java's mascot, Duke, juggling a number of jelly beans. Here's what we do:

  • Click on the Juggler bean in the ToolBox, and then click on the BeanBox window to drop it there. At this point, you should see the following:

where the juggler is seen to be actively juggling those beans.

  • Add two "Explicit Button" beans to the BeanBox window. Set the Label property of one to Start and the other to Stop. Also, set the font size of each button to be 14 pt. Now, our BeanBox should look something like:

  • Now, let's hook up the buttons to start and stop the image animation. First, select the Stop button. Then choose the Edit->Events->button push->actionPerformed menu item. Now, when you move the mouse over the BeanBox window, you'll see a red line growing from the Stop button. Now, select the Juggler bean, and up will pop a dialog like this:

Select the stopJuggling method from this dialog, and the BeanBox will generate and compile an adapter class that looks something like:

// Automatically generated event hookup file.

package tmp.sunw.beanbox;
import sunw.demo.juggler.Juggler;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ___Hookup_162f488237 implements java.awt.event.ActionListener, 
					  java.io.Serializable 
{
    public void setTarget(sunw.demo.juggler.Juggler t) 
    {
        target = t;
    }

    public void actionPerformed(java.awt.event.ActionEvent arg0) 
    {
        target.stopJuggling();
    }

    private sunw.demo.juggler.Juggler target;
}

Do the same thing with the Start button (but choose the startJuggling method),

Now, you should have a simple application that starts the juggler when you click on the Start button, and stops it when you click on the Stop button.

It should look something like:

The above is a live applet. It should look something like the following image:

If you can't see the applet, then try to upgrade your browser to see whether that's the problem.

Using The BeanBox to Generate an Applet

In fact, I used the BeanBox to generate the above applet -- I did not write one line of code!

To have the BeanBox generate an applet, you do the following:

  • Once you have set up the beans and their interactions, choose the File->MakeApplet ... menu item and you will see the following dialog:

As you can see, it allows you to specify the JAR file to create, and the name of the applet class to generate.

The BeanBox in BDK 1.0 will do the following:

  • Generate a JAR file containing class files and serialized data. In the above case, it contains:
    • Manifest.mf
    • JugglerApplet.class
    • JugglerAppletData
    • The two generated adapter classes
  • Copy a set of JAR files into the same directory as the applet JAR file. These JAR files are for the beans the applet uses.
  • A test HTML file that uses the JAR file (and any other JAR files required).

    Here is what the generated HTML file looked like for the above applet:

<html>
<head>
<title>Test page for JugglerApplet as an APPLET</Title>
</head>
<body>
<h1>Test for JugglerApplet as an APPLET</h1>
This is an example of the use of the generated
JugglerApplet applet.  Notice the Applet tag requires several
archives, one per JAR used in building the Applet
<p>
<applet
    archive="./JugglerApplet.jar,./support.jar
        ,./juggler.jar
        ,./buttons.jar
    "
    code="JugglerApplet"
    width=259
    height=234
>
Trouble instantiating applet JugglerApplet!!
</applet>

This HTML file can be used as a template for how to construct the applet tag in your real HTML page, or it may be used directly, using either a browser or appletviewer to see the applet run.

  • A subdirectory with Java sources and a makefile
  • A readme file with detailed information about the generated applet and the files involved. 
 
The page was last updated February 19, 2008