# Adding a Mail Dialog, Part 1

In this example, a button labeled Email is added to the card file. When clicked, the Email button opens a dialog box that allows the user to write a message and close the dialog box. The dialog box contains a component called Mail Panel that is created using GUI builder. The following steps occur in this example:

- Laying out the Mail Panel component
- Adding behavior to the mail panel

To create the Mail Panel component:

1. Create a new GUI project for the mail panel.
2. Choose Project -> Edit.
3. Click the Build tab and type in the root directory of the class hierarchy.

       On Solaris(TM):
       home-dir/.jws2.0/ImportedComponents/classes

       On Windows 95 and Windows NT:
       home-dir\jws20\ImportedComponents\classes

4. In the default panel layout window, add the following components to the grid:
   - Text Label (3)
   - Single-line Textfield (2)
   - Multi-line Textfield (1)
   - Text Button (2)
5. Add labels and component IDs.

   The following component IDs were made for the Mail dialog in this example:

     `toLabel`
     `subjectLabel`
     `messageLabel`
     `toTextfield`
     `subjectTextfield`
     `sendButton`
     `cancelButton`

The finished layout should look like this:

Save the layout and generate the Java source code by choosing GUI -> Save Generate GUI File.

In this example, behavior is only added to the Send and Cancel buttons. You can add additional operations to the example as you wish.

To add behavior to the mail panel:

1. Select the Send button and open the attribute editor.
2. Click on Edit operations.
3. Click on Insert to add an operation.
4. Click on the Action button to open the Action dialog box.
5. Select the action type, Execute Code.
6. Add code that sends a message to the card file that the Send button was clicked:

       group.postMessage(new Message(group, "Send", null));

Follow the same steps for the Cancel button, and add code that tells the card file that the Cancel button was clicked.

After the operations have been added, save and generate the source file by clicking on the Save Generate GUI File button in the main toolbar. Then build the application by clicking on the Build button in the main toolbar.

When the build completes, you can click on the Run button in the main toolbar to test the application.

See also:

  Adding a Mail Dialog, Part 2
  Laying Out the GUI Interface
  Modifying Components in the Grid
  Positioning Components in Cells
  Resizing the Window