'; zhtm += ''; zhtm += '

' + pPage + ''; zhtm += '
'; window.popUpWin.document.write(zhtm); window.popUpWin.document.close(); // Johnny Jackson 4/28/98 } //--> Java 1.2 Unleashed -- Ch 27 -- Notable Beans


Java 1.2 Unleashed

Previous chapterNext chapterContents


- 27 -

Notable Beans


Since the debut of JavaBeans, thousands of beans have been developed. Hundreds of these beans are available as off-the-shelf Java components. You can find links to many of these beans from the JavaBeans Directory located at http://www.javasoft.com/beans/directory/. In this chapter you'll take a look at some of the beans that are being developed by the Java software development community. You'll look at the HotJava HTML Component bean, a product of JavaSoft. You'll work with the RunningText bean developed by Jayakrishnan Nair, a computer science student at the University of Victoria. You'll also look at some beans from IBM's WebRunner Toolkit. If you're not currently convinced of the power of JavaBeans, you will be after this chapter.

The HotJava HTML Component

One of the most powerful bean sets on the market is the HotJava HTML Component from JavaSoft. This product consists of several beans that can be used to add Web-browsing support to window applications. It parses and renders HTML files that are loaded from the Web and includes the following features:

A trial version can be downloaded from http://java.sun.com/products/hotjava/bean/index.html. Go ahead and download it now so you can work along with the example in this section.

Installing the HotJava HTML Component

The HotJava HTML Component is easy to install. The Microsoft Windows version comes as a .zip file. UnZip the file to a temporary directory and copy the HotJavaBean.jar and TextBean.jar files to your \bdk\jars directory.

Running the HotJava HTML Component in the BeanBox

After installing HotJavaBean.jar and TextBean.jar, run your BeanBox. You will notice the following five beans have been added to the ToolBox:

We'll use three of these beans to visually design a browser in the BeanBox. Our browser won't support user authentication or URL history tracking, so we won't need AuthenticatorBean or HotJavaDocumentStack. However, you may want to experiment with these beans on your own.

1. Select the HotJavaSystemState bean from the ToolBox and click in the lower-right corner of the BeanBox. Use the properties sheet to edit the SystemPropertDefaults properties to set up any proxy servers that you may be using.

2. Select the TextBean in the Toolbox and click in the upper-left corner of the BeanBox.

3. Select the HotJavaBrowserBean in the Toolbox and click in the middle of the BeanBox. An evaluation notice is displayed. Click OK after you've read it. Resize the bean and organize the BeanBox as shown in Figure 27.1.

After completing these steps, your BeanBox should appear similar to Figure 27.1.

Now connect the HotJavaBrowserBean and the TextBean so that we can begin browsing URLs. If you are not currently connected to the Internet, now would be a good time to get online.

1. Select the HotJavaBrowserBean in the BeanBox. The bean's border is highlighted.

2. Select the Bind property from the Edit menu. The PropertyNameDialog is displayed.

3. Select the documentString property and click OK.

4. Move your mouse to the TextBean. A red line appears behind your cursor.

FIGURE 27.1. Laying out the BeanBox for the HotJava HTML Component.

5. Click on the TextBean and the PropertyNameDialog appears.

6. Click on the text property and select OK. You've now connected the documentString property of the HotJavaBrowserBean to the text property of the TextBean. We'll make the connection in the other direction as well.

7. Select the TextBean.

8. Set the text property to www.javasoft.com.

9. Select Bind property from the Edit menu.

10. Select the text property in the PropertyNameDialog and click OK.

11. Move your mouse to the HotJavaBrowserBean and click OK. Note that the red line connects the TextBean to the HotJavaBrowserBean.

12. Select the documentString property in the PropertyNameDialog and click OK.

At this point, the HotJavaBrowserBean should try to establish an HTTP connection to www.javasoft.com, as shown in Figure 27.2.

With just a few drags and drops, you've created a full-blown browser within the BeanBox. Try using the TextBean to connect to other sites. For example, enter www.yahoo.com in the TextBean. The HotJavaBrowserBean should display the Yahoo! home page. Now click on any of the links on the Yahoo! home page. The TextBean is updated with the URL of the document you selected. When you are finished exploring the TextBean and HotJavaBrowserBean, exit the BeanBox.

FIGURE 27.2. Browsing the Web with the HotJava HTML Component.

The RunningText Bean by Jayakrishnan Nair

You would expect a company like JavaSoft to come up with an impressive bean. However, you don't have to be a large company to build useful beans. Jayakrishnan Nair, a computer science student at the University of Victoria in Victoria, Canada, developed the RunningText bean that you'll study in this section. The RunningText bean provides a great example of animation and is perfect for Web page advertising. It allows you specify the text that you want to scroll, along with its foreground and background colors. Best of all, you can download the bean from Jayakrishnan's Web site at http://csr.csc.uvic.ca/~jk/java.html. Go ahead and download it so you can use it in the following example.

Installing the RunningText Bean

The RunningText bean, like most beans, is simple to install. It comes in a file named RunningText.jar. To install the bean, just copy RunningText.jar to the \bdk\jars directory to make it available to the BeanBox.

Running the RunningText Bean in the BeanBox

The RunningText bean is easy to use. Launch the BeanBox program and click on the RunningText bean in the ToolBox. Then click the center of the BeanBox. The RunningText bean should appear as shown in Figure 27.3.

FIGURE 27.3. The initial display of the RunningText bean.

The RunningText bean is immediately up and running in your BeanBox. Look at the bean's property sheet. You'll see that it allows you to set the following properties:

Experiment with these properties to learn how you can tailor the bean's behavior.

1. Set the text property to "JavaBeans".

2. Set the bgColor property to yellow.

3. Set the fgColor property to blue.

4. Set the shadowOn property to false.

5. Set the fontSize property to 32.

You should notice that the bean's behavior is changed in the BeanBox instantly when you make these modifications.

The RunningText bean is a great way to add advertisements to Web pages. You may want to experiment further by adding the RunningText bean to an applet and displaying it in one of your Web pages. When you are finished with the RunningText bean, exit the BeanBox.

Beans by IBM

One of the most committed developers of beans is IBM. It has created dozens of handy beans and makes them available through its fine Java software development tools. In particular, the WebRunner Toolkit includes a number of beans that are great for building applets and window applications. Some of the beans available through the WebRunner Toolkit include the following:

Trial versions of these beans are available from http://www.software.ibm.com/ad/webrunner/WRBeans.html. Go ahead and download the Gauge beans. We'll use them in the following example.

Installing the Gauge Beans

The Gauge beans are contained in a file named gauges1e.tgz. The filename may vary for later versions of the Gauge beans. The file is a tarred, gzipped file. Use a program like WinZip to extract the files contained in gauges1e.tgz to a temporary directory. You'll notice that IBM supplies copious documentation for these beans. The actual beans are extracted to the \Jars subdirectory. Copy Gauges.jar and GaugeTest.jar to the \bdk\jars directory to make the beans available to the BeanBox.

Running the Gauge Beans in the BeanBox

After installing the .jar files in the \bdk\jars directory, launch the BeanBox application. You should notice that the following beans have been added to the toolbox:

Oscilloscope--An oscilloscope-like value display.

We'll start with the first four beans.

1. Place a GaugeTest bean in the upper-right corner of the BeanBox.

2. Place a Needle bean in the upper-left corner.

3. Place a LightBulbIndicator bean under the Needle bean.

4. Place a TraceRecorder bean under the GaugeTest bean.

At this point, your BeanBox should look like Figure 27.4.

Now connect the beans together. Bind the value property of the GaugeText bean to the value properties of the other three beans. Do this one bean at a time.

1. Select the GaugeTest bean.

2. Select the Bind property from the Edit menu.

3. Select the value property in the PropertyNameDialog.

FIGURE 27.4. Laying out the first four Gauge beans.

4. Click on the bean that you want to connect to.

5. Select the value property in the destination bean's PropertyNameDialog.

You'll notice that the value of the GaugeTest bean is reflected in the values of the other three beans, as shown in Figure 27.5.

FIGURE 27.5. The GaugeTest bean drives the Needle, LightBulbIndicat- or, and TraceRecorder beans.

Now clear the BeanBox and examine some of the other Gauge beans.

1. Place the GaugeTest bean in the upper-right corner of the BeanBox, as before.

2. Place the BarIndicator bean to the left of the GaugeTest bean.

3. Set the background property of the BarIndicator to white so that you can see it against the background of the BeanBox.

4. Place the RAGNeedle bean underneath the BarIndicator bean.

5. Place the RollingCounter bean underneath the GaugeTest bean.

6. Place the LEDCounter bean underneath the RollingCounter bean.

7. Place the BlockIndicator bean underneath the RAGNeedle bean.

8. Set the background property of the BlockIndicator to white.

9. Place the Thermometer bean under the LEDCounter bean.

10. Place the Oscilloscope bean under the BlockIndicator bean.

Your BeanBox should now look similar to the one shown in Figure 27.6.

FIGURE 27.6. Laying out the rest of the Gauge beans.

Now connect the value property of the GaugeTest bean to the value properties of the other beans. When you finish, the value of the GaugeTest bean will drive the value of the other beans, as shown in Figure 27.7.

FIGURE 27.7. The gauges are all working in unison.

Summary

In this chapter you took a look at some of the beans that are being developed by the Java software development community. You learned how JavaSoft's HotJava HTML Component bean can be used to embed Web-browsing capabilities into any window application. You worked with the RunningText bean developed by Jayakrishnan Nair and learned how it can be used to add animated text to applets and applications. You also looked at some of the nifty Gauge beans from IBM's WebRunner Toolkit. In the next chapter, "Using InfoBus," you'll learn how Infobus is used to facilitate communication between beans.


Previous chapterNext chapterContents

© Copyright, Macmillan Computer Publishing. All rights reserved.