Example of Code Generated from Visual Composite


GenerationTest applet

This simple Hello World! applet contains the following beans. The applet subclass itself is represented by the dotted rectangle.

All the finished applet does at run time is split the text value of the Label bean into two substrings and copy each substring to an entry field.

Suppose the composite is saved after the beans have been dropped and edited for initial content. VisualAge generates field declarations and accessor methods as follows:

VisualAge also generates the following applet methods:

The first connection, connPtoP1, links the text property of MyHello to the this property of MyString. Neither feature is bound. When you save the composite, VisualAge generates these additional methods:

Connections from the actionPerformed event of SplitButton to the text property of each TextField bean (connEtoM1 and connEtoM2) reset the text displayed in each entry field. By default, no event data is passed to the target of the connection, so each connection requires input for the new value of text. Parameter connections (connEtoM3 and connEtoM4) pass in these values: the value property of each push button connection is connected to the substring(int, int) method of MyString. The exact character indexes are provided as connection properties of connEtoM3 and connEtoM4.

Now when you save the composite, VisualAge generates these additional methods:

Suppose you then separate all text into a list bundle. If you opt for a new resource bundle, VisualAge creates a resource class for you in the same package. In addition, the get methods are regenerated to retrieve the appropriate resource instead of using hardcoded text. The call for setting MyHello to "Hello, World!" looks like this:

ivjMyHello.setText(java.util.ResourceBundle.getBundle
   ("CodeGen.HelloResources").getString("rHelloWorldText"));


Related concepts
Generated Code
Generated BeanInfo Descriptor Code (an advanced topic)
Code Generated from Visually Composed Beans
How Generated Code Coexists with User-Written Code
Internationalization in VisualAge

Related procedures
Exporting to the file system
Working with Beans Visually
Connecting Beans
Separating Strings for Translation

Related references
Example of Generated Feature Code
Beans for Visual Composition