Sample: BookmarkList

Objectives

This sample illustrates how to build an application using visual composition.

Before you begin

The Link to URL Button only works if BookmarkList is run in a web browser that supports JDK 1.1.

Description

This sample illustrates using features of visual composition for the following tasks: This sample lets you create a non-persistent list of URL bookmarks.

The BookmarkList class in this package subclasses java.applet.Applet.  It uses a BorderLayout as its layout manager. Its North component is a Panel, which contains a Label and a TextField.  A GridLayout is used to manage the layout of this nested Panel. The Center component of the BorderLayout is a List, and the East component is another Panel. This nested Panel contains a set of Buttons and uses a GridLayout as its layout manager.

The Buttons enable users to add URL bookmark entries to the List and to link to and delete selected entries.  These Buttons are dynamically enabled/disabled.  For example, the Button labeled, "Add URL to list", is only enabled when the URL address field contains text.

In addition to showing typical button-driven list manipulation it shows how to use the appletContext property of an applet.  Once you add a bookmark to the list, you can select it and press the Link button.  The link is made by calling showDocument on the applet context.  If an exception occurs on the link, then showStatus is called on the applet context to display a message in the status area of the browser.

Running the BookmarkList Sample

To run the sample:
  1. Select the BookmarkList class from the Projects page
  2. Select the Run button on the tool bar
To run the sample in a browser that supports JDK 1.1:
  1. Select the BookmarkList from the Projects page
  2. Click mouse button 2
  3. Select Export
  4. Select Directory
  5. Click Next
  6. Select the .class check box to export the class file
  7. Select the .html check box to generate html
  8. Execute the generated html in your browser

To build the BookmarkList sample:

There is only one bean in the BookmarkList sample, and it is called BookmarkList.  Follow the instructions below.

Building the BookmarkList class

  1. Create the BookmarkList class as follows:
  2. The Visual Composition page of the class browser will be displayed, where you can build the user interface as follows:
  3. Create a tear-off property
  4. Save the bean and generate code for it:
  5. Create a method:
  6. Add some code:
  7. Make connections to set properties and invoke methods as follows (see Connection Syntax ):
  8. Reorder some connections:
You're now ready to run the application.  Have fun!