Getting Started


Defining the address panel

The objective of this section is to familiarize you with creating reusable visual parts and using them with VAGen parts. This exercise focuses on the following tasks:

Creating a reusable bean

You will build a panel and add labels and fields for address information. Figure 91 shows the panel you will define.

Figure 91. Address Panel

Address Panel

  1. On the Workbench Projects tab, select the tutorial package.
  2. From the Selected menu, select Add>Class.

    The Create Class SmartGuide is displayed.

    Tip:Choices on the Selected menu are the same as those on the context menu displayed when you select a package and click mouse button 2.
  3. In the Class name field, type the name ReusableAddressBoxView.
  4. In the Superclass field, type the class javax.swing.JPanel.
  5. Select Compose the class visually.
  6. Select Finish.

    The new visual part is displayed in the Composition Editor.

Adding parts to the address panel

In this section of the tutorial, you will add labels and fields for street, city, state, and zipcode.

Complete the following steps to add parts to the Address panel:

  1. Resize the address panel by selecting it and dragging the selection handles on the right or left side.

    Alternatively, you can resize the panel by double-clicking on it to display the Properties window where you can expand the constraints field and set the values in the width and height fields to 400 and 100 respectively.

  2. From the Beans palette, select JLabel JLabel.
  3. Drop the part on the panel.
  4. Double-click the label you dropped.

    The Properties window is displayed.

  5. In the text field type Street.
  6. Select JTextField JTextField.
  7. You will need to resize the JTextField because it is small by default.
  8. Repeat the previous steps to create labels and associated text entry fields for City, State, and Zip as shown in Figure 91.

    For more detailed information about arranging visual parts see "Arranging visual parts".

Promoting features of the reusable part

If you want to access any information in the Address panel from another visual part, you must add the appropriate features to the bean's public interface. In this case, the features needed are the properties for the text field beans. In this section, you will add properties for all four beans (Street, City, State, and Zip) to the public interface.

For more complete information on topics covered in this section, refer to the VisualAge for Java online help.

To promote bean features to the public interface, perform the following steps:

Note:Before you promote bean features, you should rename the beans so that you will recognize them when you need to access them from other beans. To rename a bean, select it with mouse button 2 to display the context menu. Select Change Bean Name and type a name in the New bean name field.
  1. Select the Street entry field and rename it to StreetField.
  2. Select the Street entry field with mouse button 2. From the context menu, select Promote Bean Feature.

    The Promote features from window is displayed.

  3. On the Promote features from window, select the property text and select the >> button.

    StreetFieldText is displayed in the Promoted features list.

  4. Select OK.
  5. Repeat the above steps for the City, State, and Zip entry fields, using the names CityField, StateField, and ZipField, respectively.

    The text property feature of each of the four beans has been added to the public interface. Now these properties can be accessed by other beans.

  6. Select Bean>Save Bean.
  7. Close the Visual Composition Editor.

Now you are ready to embed the address box in your tutorial view and add VAGen logic parts.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]