Creating a Form

   

You can add a form to your application through the Project menu.

Objects that include components and controls can be dragged from the Toolbox to the form. The form is persisted as a block of source code that defines an instance of the WFC Form class. The default Form class contains:

The Forms Designer generates this code based on values set in the Properties window for each control and the form itself. Be careful when modifying the initForm method because the Forms Designer also reads this code when displaying the form. Also avoid conditionals, such as if, while, and switch statements, and component methods. If you modify the initForm code, restrict changes to properties that begin with set, and restrict values to constants. Do not use variables to set values.

For example:

Correct   setSize(10,100);
Incorrect   x=10; y = 100; setSize(x,y);

To create a form

  1. Open an exiting project, or create a new project.

  2. In Project Explorer, select the name of your project.

  3. On the Project menu, click Add Form.

  4. In the Add Item dialog box, click either the New or Existing tab. For this example, click the New tab.

  5. In the Add Item dialog box, click the Form icon.

    This template creates a class capable of hosting controls.

  6. In the Name box, edit the name of the class file. The default name is Form1.java.

  7. Click Open.

    The form window is displayed, showing the form surface.

The form is automatically opened in design mode if you are creating a new form from a template.

If the Forms Designer is not currently active, use the following procedure to open it.

To view the form in the Forms Designer

By default, controls are aligned to the form grid. Set grid options using the Tools command on the Options menu. Form properties can be directly modified in the property page for the form.

The Toolbox contains WFC Controls and can include other tabs containing ActiveX and custom controls.

Once you have the basic form template, you are ready to add controls to it.