Sample: CustomerInfo

Objectives

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

Description

This sample illustrates using features of visual composition for the following tasks: This package is full of beans!  It contains two nonvisual beans, Address and Customer, that represent a model of data and two views for those beans, AddressView and CustomerView. The Address bean is referenced in the AddressView. Address is also used as a property in the Customer bean. The CustomerView contains an AddressView within its view and references a Customer bean. The CustomerInfo sample, which extends java.awt.Frame, brings these models and views together. It also uses another sample bean: an ObjectList that looks like a java.awt.List but uses and maintains any object, not just strings.

Running the CustomerInfo Sample

To run this sample:
  1. Select the CustomerInfo class from the Projects page.
  2. Select the Run button on the tool bar.

To build the CustomerInfo sample

The classes that are part of the CustomerInfo sample should be built in the following order:
  1. Address
  2. AddressView
  3. Customer
  4. CustomerView
  5. CustomerInfo

Building the Address class

  1. Create the Address class as follows:
  2. Add some properties:
  3. Add some methods:
  4. Add method features:
You could have created the clone and copyFrom methods from the BeanInfo page.  They would have been defined as method features, and you could have avoided this last step.

Now you can close the class browser for the Address class.
 

Building the AddressView class

  1. Create the AddressView 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. Add a nonvisual bean
  4. Promote a feature
  5. Make connections to set properties and invoke methods as follows (see Connection Syntax ):
  6. Save the bean and exit:
You have just created a reusable view that can be used to display and edit an Address. Just drop the AddressView in a visual bean. Also drop an Address and connect the Address bean to the address attribute of the AddressView bean.

Building the Customer class

  1. Create the Customer class as follows:
  2. Add some properties:
  3. Add some methods:
  4. Add method features:
You could have created the clone and copyFrom methods from the BeanInfo page.  They would have been defined as method features, and you could have avoided this last step.

Now you can close the class browser for Customer.

Building the CustomerView class

  1. Create the CustomerView 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. Add a nonvisual bean:

  4. The nonvisual Customer bean will be used as a variable that will reference specific instances of Customer as needed.
  5. Promote a feature
  6. Make connections to set properties and invoke methods as follows (see Connection Syntax ):
  7. Reorder the tabbing sequence:
  8. Save the bean and exit:
You have just created a reusable view that can be used to display and edit a Customer. Just drop the CustomerView in a visual bean. Also drop a Customer and connect the Customer bean to the customer attribute of the CustomerView bean.

Building the CustomerInfo class

  1. Create the CustomerInfo 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. Save the bean
  4. Add a nonvisual bean:
  5. Add a method:
  6. Make connections to set properties and invoke methods as follows (see Connection Syntax ):
As beans are added to the Visual Composition Editor, the Class Path is updated to include any referenced classes and their projects.  In this sample a JOptionPane is referenced in code, but is not dropped in the Visual Composition Editor so the appropriate project is not included in the Class Path.  To let VisualAge determine which projects are required and to update the Class Path accordingly, do the following: The sample is now complete and ready to run!