Java 1.2 Unleashed

Previous chapterNext chapterContents


- 25 -

The JavaBeans Development Kit


In the previous chapter you covered the basics of component-based software development. This background information will help you understand how the tools of the JavaBeans Development Kit (BDK) work. However, there is no substitute for hands-on experience. In this chapter you'll download and install the BDK and take a tour of what it has to offer. You'll learn how to use the BeanBox to develop and test your beans and investigate some of the example beans included with the BDK. When you finish this chapter, you'll know how to use the BDK to begin your own beans development.

Downloading and Installing the BDK

The BDK is freely available from the JavaBeans home page, which is located at http://java.sun.com/beans/index.html. This Web page also contains links to JavaBeans technical specifications and information on future plans for JavaBeans. Follow the links to the BDK 1.0 download page and download the version that is appropriate for your operating system. The rest of this section assumes that you are using Windows 95 or NT.

The Windows version of the BDK is available as a self-installing executable file. Just double-click the file's icon to start the installation program. Follow the installation instructions and install it in the default directory (c:\bdk).

Inside the BDK

The BDK provides several examples of JavaBeans, a tutorial, and supporting documentation. But most important, it provides a tool, referred to as the BeanBox, that can be used to display, customize, and test the beans that you'll develop. The BeanBox also serves as a primitive visual development tool. You'll use the BeanBox to see the important aspects of visual component-based software development as it applies to JavaBeans. Download and install the BDK before continuing on to the next section. Once you've installed the BDK, restart your system to make sure that all installation changes take effect.


NOTE: Through the rest of the chapter, it will be assumed that you've installed the BDK in its default location, the c:\bdk directory. If you install the BDK in a different directory, you'll have to map between c:\bdk and your installation directory.

Using the BeanBox

The BeanBox of the BDK is an example of a simple visual development tool for JavaBeans. It is located in the c:\bdk\beanbox directory. Change to this directory and start the BeanBox as follows:

c:\bdk\beanbox>run

The BeanBox application loads and displays three windows labeled ToolBox, BeanBox, and PropertySheet, as shown in Figures 25.1, 25.2, and 25.3.

The ToolBox window contains a list of available Java beans. These beans are components that can be used to build more complex beans, Java applications, or applets.

FIGURE 25.1. The ToolBox window.

FIGURE 25.2. The BeanBox window.

FIGURE 25.3. The PropertySheet window.

Visual software development tools, such as the BeanBox, allow beans to be visually organized by placing them at the location where you want them to be displayed. Click the Juggler bean in the ToolBox window and then click in the BeanBox; the Juggler bean is placed in the BeanBox, as shown in Figure 25.4. The Juggler bean juggles when it is placed in the BeanBox.

FIGURE 25.4. Adding a bean to the BeanBox.

Note that the PropertySheet is updated to display the properties of the Juggler bean (see Figure 25.5). You can customize the Juggler bean by changing its properties. Change the animationRate property to 500, as shown in Figure 25.6. Note how the Juggler slows the rate at which it juggles the beans.

FIGURE 25.5. The Juggler's PropertySheet.

FIGURE 25.6. Changing the Juggler's animationRate property.

Now add a couple of buttons to the BeanBox. Select an OurButton bean in the ToolBox and then place it in the BeanBox, as shown in Figure 25.7. A button labeled Press is displayed. Use the button's property sheet to change its label to Start, as shown in Figure 25.8. Now create a second button labeled Stop, as shown in Figure 25.9.

FIGURE 25.7. Adding a button to the BeanBox.

FIGURE 25.8. Editing the button's label.

FIGURE 25.9. Adding a second button to the BeanBox.

By now you can see where this application is going. You're going to use the Start and Stop buttons to control the animation. To do this, you'll connect the Start button's actionPerformed() event handler to the startJuggling() method of the Juggler bean and the Stop button's actionPerformed() event handler to the stopJuggling() method of the Juggler bean.

Click the Start button and then select Edit | Events | Action | ActionPerformed from the BeanBox menu bar, as shown in Figure 25.10. A red line is now shown emanating from the Start button. This line represents a logical connection from the Start button's actionPerformed() event handler. Click the Juggler bean to close the connection. When you do, the EventTargetDialog box, shown in Figure 25.11, is displayed. This dialog box lists the interface methods of the Juggler bean. Select startJuggling. By doing so, you connect the clicking of the Start button to the startJuggling() method via the actionPerformed() event handler of the Start button bean. The EventTargetDialog box notifies you that it is compiling an adapter class. The BeanBox creates a special class, referred to as an adapter class, to connect the clicking of the button with the startJuggling() method of the Juggler. It must compile this class and add it to the running BeanBox to support this connection.

FIGURE 25.10. Selecting the actionPerformed() event handler.

FIGURE 25.11. Connecting to the startJuggling() method.

Now that you know how to associate events with interface methods, connect the Stop button to the stopJuggling() method of the Juggler bean. Click the Stop button and select Edit | Events | action | actionPerformed from the BeanBox menu bar. Connect the red connector to the Juggler bean and select the stopJuggling method.

Now you can have some fun with the Juggler. Click the Stop button to stop the juggling and click the Start button to get it going again.

Understanding the Example Beans

You should be impressed by how easy it was to develop an interesting (or at least entertaining) application using the BeanBox and JavaBeans. In fact, you didn't have to write a single line of code to create the application. That's the power of component-based software development. Given a good stock of beans, you can quickly and easily assemble a large variety of useful applications.

In the example of the previous section, you learned how to use the OurButton and Juggler beans. The ToolBox that comes with the BeanBox lists 16 beans. I recommend that you play around with these beans to familiarize yourself with how they work. You studied the theory behind component-based software in the previous chapter. Now is the time to get some practical experience to back up your theoretical understanding. Try to see how the BeanBox and the example beans support the component-based model described in Chapter 24.

Just to whet your appetite, what follows is a short description of the beans that are in the ToolBox.

Now fire up the BeanBox and try out some of these beans. You'll learn how the java.beans packages support the implementation of the capabilities that you observe with the BeanBox.

Other Bean Development Tools

The BeanBox is a fairly basic visual design tool, yet it provides the important features of visual component-based software development. There are a number of very good visual design tools that support Java software development. If you're serious about developing your own beans, or using them to create applets or applications, it's recommended that you obtain one of these high-end tools. They'll save you plenty of time and effort in the long run. A list of available tools is available from JavaWorld at http://www.javaworld.com/javaworld/tools/jw-tools-index.html. Chapter 56, "Java Development Tools," describes the best of these tools. Table 25.1 provides a summary of popular tools that support bean development.

TABLE 25.1. BEAN DEVELOPMENT TOOLS.

Tool Vendor Retail Price Description
Java Workshop 2.0 Sun Microsystems, Inc. $110 Complete IDE that supports applet, application, and bean development
Java Studio Sun Microsystems, Inc. $69 Bean-oriented visual development tool
JavaPlan Sun Microsystems, Inc. $3,995/seat Enterprise-wide Java development tool; supports bean development
Visual Café for Java 2.5 Symanted, Inc. $99.95 to $499.95 Family of highly-rated visual development tools oriented around beans
Visual Age for Java IBM Free to$99.95 Bean-oriented visual development toolset
Visual J++ Microsoft, Inc. $99.95 Microsoft's answer to Java software development
Jbuilder Borland, Inc. $99.95 to $2,495 Suit of bean-oriented Java development tools.
Super Mojo Penumbra Software, Inc. $39.95 Popular Java visual design tool.
JDesignerPro BulletProof Corporation $695 Application development environment and middleware
SuperCede Java Edition SuperCede, Inc. $29.95 A cost-effective Java visual design toolset
Jamba Interleaf, Inc. $149 Visual authoring environ- ment aimed at minimiz- ing the need for coding

Summary

In this chapter you downloaded and installed the BDK and took a tour of its contents. You learned how to use the BeanBox to develop and test beans and looked at some of the example beans included with the BDK. You also learned about some of the other bean development tools. In the next chapter you'll study the classes of the java.beans packages and learn how to use them to develop your own beans.


Previous chapterNext chapterContents


© Copyright, Macmillan Computer Publishing. All rights reserved.