Generating Java Source Code

Once you have laid out your window, you must generate the Java code that you will integrate with your program.

To generate code for your layout:

When you generate code, GUI builder automatically saves your layout.

When you generate code from your layout, the following files are generated in the project's source directory:

project.gui
Contains the code that describes the GUI. This file is updated (or created) whenever you save the layout. One .gui file is generated per group. A Java WorkShop project can contain only one group, but projects can contain other projects.

projectRoot.java
Contains the code necessary to initialize the components for the group.


Do not make changes to this file--it is recreated every time you generate the interface.

projectOps.java
Contains the operations for the group. This file is generated only if you have defined operations on one or more of the components in the group. Operations are described in Operations Dialog Box.


Do not make changes to this file--it is recreated every time you generate the interface.

projectMain.java
Contains the main method that is used to run the group as an applet or a standalone application.


Do not make changes to this file--it is recreated every time you generate the interface.

project.java
Contains a template for the group. This file is generated only once--you modify this file to implement event handlers, action handlers, and other functionality.

Error Checking

During code generation, some error checking is done on the .gui file. The attribute types are checked for correctness, and the attribute values are matched against the attribute types. However, the attribute types are not checked against the attribute names. Also, the attribute names are not checked against the shadow or group inside which they are defined.

Errors of this nature are uncommon in a .gui file. This kind of error could be introduced by hand-editing the .gui file or by modifying the attributes of a shadow or group class that is used by an existing .gui file.

These errors are not caught because the code generator does not load any of the shadow or group classes listed in the .gui file. It is much faster to generate the code without loading all the shadows and groups, and not loading the groups avoids dependency problems.

The code generator instantiates all the shadows and groups during generation. Errors such as bad attribute names and attribute type mismatches are caught. The generator will throw an error if one of the group or shadow classes that it needs does not exist.

See also:

Laying Out the Interface
Adding Operations to Components
GUI Builder Runtime Classes
Creating Menus
What Are Groups and Shadows?
More On Groups and Shadows

Visual Java GUI Builder API Documentation
Visual Java GUI Builder Runtime Packages
Class Hierarchy
Index of All Fields and Methods