Generate 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, use either of these two methods:


When you generate code, Visual Java automatically saves your layout.

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

<ProjectName>.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.

<ProjectName>Root.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.

<ProjectName>Ops.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.

<ProjectName>Main.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.

<ProjectName>.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.

It is uncommon for an error of this nature to exist in a .gui file. There are a few ways this kind of error could be introduced, such as hand-editing the .gui file or 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. The shadows and groups are not loaded because of performance and dependency issues. It is much faster to generate the code without loading all the shadows and groups. The more important reason for not loading the groups is to avoid the dependency problems that this would cause.

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


See also:

Visual Java Overview
The Visual Menu
Visual Java Components
Laying Out GUI Interfaces
Adding Operations (Filters and Actions)
Visual Java Runtime Classes
Creating Menus
Adding Custom Components and Windows
Using Groups and Shadows (Basic)
Using Groups and Shadows (Advanced)
Visual Java API Documentation
Visual Java Runtime Packages
Class Hierarchy
Index of all Fields and Methods