Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 
Training Index

Introduction to the JavaBeans API, Magercise 1 Help
The Beans Development Kit

by John Zukowski, MageLang Institute

[Magercise 1 | API Docs | Short Course | Magercises]

Help is available for each task.

Task 1

Start the BeanBox, either from a command shell or a graphical file navigator such as Windows Explorer.

With a command shell, change directories to the BDK installation directory. From there, change directories to the beanbox subdirectory and execute run.bat (Windows) or run.sh (UNIX). The run script will start the BeanBox. Also, from Windows Explorer you can simply navigate to the beanbox directory and double-click run. Note that for some releases of the BDK, the Windows install program automatically adds a BDK/BeanBox entry to the Start menu.


The command sequence for starting the BeanBox is:

cd beanbox
run             [Windows NT/95] or
run.sh          [UNIX]

Task 2

The BeanBox consists of three windows: the palette, the worksheet area, and the property sheet for the currently selected Bean. The palette and property sheet windows appear only in design mode. To hide/show them, select the design-mode menu item under the "View" menu. For this Magercise, they should be visible.

If you are using BDK 1.1, you get an optional fourth window, called the method tracer.


The BeanBox windows should be similar to the following, except larger:

Task 3

The currently selected Bean has a dashed line around it (initially, the worksheet object itself). The property sheet lists the properties for the currently selected Bean. To change a property, first select it from the sheet. Selecting a property activates a custom property editor, if available; otherwise, it simply sets the focus to the text-field object for text-oriented property specification.

For example, if you click on the "background" property, the BeanBox will activate a color editor. If you click on the "Abcde..." property, it will activate a font editor. The "name" property allows you to set an instance name for the currently selected object.

For now, simply change the background color of the worksheet to white.


You can specify custom colors with comma-separated red-blue-green (RGB) color values (from 0 to 255) in the text field, or you can simply select a color, for example, white, from the drop-down list.

Task 4

To place something on the worksheet, select it from the palette (with a single mouse click) and place it on the worksheet (with a second single mouse click). First, experiment with one of the command buttons. You can then try several other Beans.


There is no drag-and-drop behavior from the palette to the worksheet. When you select a Bean from the palette (single click), the cursor changes to a cross-hair shape. Then, you simply pick a location on the worksheet to deposit the Bean and click again.

To move a Bean, move the cursor near the top edge until it changes to a four-way cursor. At this point, you can drag the object over the worksheet. To resize a Bean, move the cursor near a corner until it changes to a diagonal, two-way arrow. At this point, you can resize it in both directions simultaneously. To delete a Bean from the worksheet, select it and then choose "Cut" from the "Edit" menu.

Task 5

Next, take a look at the ExplicitButton Bean. First, add an instance of this Bean to the worksheet. Then, choose "Report" from the "Edit" menu. Note the descriptive data that is displayed in the command window where you started the BeanBox. Optionally, if you are familiar with command window operations for redirecting output to a file, capture the output to a text file and examine it.


The text output describes the properties and events supported by this Bean. For a given Bean, you should find a correspondence between the data reported in the text output and both the properties listed in the property sheet and the events available from the "Edit" menu.

Task 6

Next, clear out the BeanBox to prepare for the main task, configuring a juggler Bean with two controls. Simply select "Clear" from the "File" menu. (Note that the BeanBox doesn't warn you that the worksheet contents have not been saved. You can also accidentally exit the BeanBox without getting a save-your-work prompt--you will lose whatever work you've done.)


Task 7

The next task is to configure start and stop controls for a Juggler Bean. First, select and place a Juggler and two OurButton Beans on the worksheet.


Task 8

Next, change the label for either OurButton Bean to "Start" and connect its action-performed functionality to the Juggler Bean's start-juggling functionality.


First, select an OurButton instance. Then,

  • Change the label to "Start" via the property sheet
  • Select the "Edit" menu
  • Select the "Events" submenu
  • Select the "action" submenu
  • Select the "actionPerformed" menu item

These operations enable a rubberband-like red line that you drag to the target, in this case, the juggler Bean:

  • Attach the red line to the juggler Bean by selecting it
  • Select the "startJuggling" functionality from the dialog's list
  • Select the "OK" button

Task 9

Next, change the label for the other OurButton Bean to "Stop" and connect its action-performed functionality to the Juggler Bean's stop-juggling functionality. After setting up these connections, you will be able to use the two command buttons to control the juggling operation.


First, select the other OurButton instance. Then,

  • Change the label to "Stop" via the property sheet
  • Select the "Edit" menu
  • Select the "Events" submenu
  • Select the "action" submenu
  • Select the "actionPerformed" menu item

These operations enable a rubberband-like red line that you drag to the target, in this case, the juggler Bean:

  • Attach the red line to the juggler Bean by selecting it
  • Select the "stopJuggling" functionality from the dialog's list
  • Select the "OK" button

Task 10

Lastly, you can save your work as an applet using the "MakeApplet..." command, to use it outside the BeanBox.


Select "MakeApplet..." from the "File" menu. Save the applet and related files in the default BeanBox "tmp" directory, or choose an alternate location. Note that if you provide a name for the JAR file, you must explicitly specify the ".jar" extension.

Task 11

You can now exit the BeanBox and run the applet with appletviewer from the directory where you saved it.


Several files are saved as part of the "MakeApplet..." operation, all of which are required; see the read-me file. You can view the saved worksheet Beans with appletviewer using the supplied HTML file.

Return to Magercise 1

Copyright © 1998-1999 MageLang Institute. All Rights Reserved.


[ This page was updated: 27-Oct-99 ]

Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-99 Sun Microsystems, Inc.
All Rights Reserved. Legal Terms. Privacy Policy.