# Adding a Mail Dialog Box, Part 2

This part of the mail dialog box example contains the following steps:

- Adding the Mail Panel component to the palette
- Putting the mail panel into a dialog box
- Calling the Mail dialog box from the card file's Email button
- Testing the new Mail dialog box feature

To add the Mail Panel component to the palette:

1. Select the card file project from the project manager.
2. Choose GUI -> Customize Palette.
3. Click on the Shadow tab.
4. Enter the class name for the component, `MailDialog`, a descriptive name for the component.
5. Assign an icon for it by giving a path for the icon.

   When assigning an icon, use an absolute path in the form of a fully qualified URL (for example: `file:/C:\home\images\icon.gif`).

6. Select the Additional palette folder in the Palette Components list.
7. Click Add to insert the component into the palette folder.

   Use the Up Arrow and Down Arrow buttons to position the component in the actual palette folder.

8. Click OK in the Import Components to Palette dialog box to add the component to the GUI builder palette.

To put the mail panel in a dialog box:

1. Choose GUI -> Add New Window.
2. Select Empty Dialog.
3. Reduce the gridbag layout to one cell.
4. Add the Mail Panel component to the cell.
5. Open the attribute edior for the dialog box (click in the area around the grid).
6. In the title box, type a window title for the Mail dialog box.
7. Set the visible attribute to false so the dialog box does not automatically appear with the card file.

To call the Mail dialog box from the card file:

1. Open the layout for the card file.

   You need to be in the card file project; click on the card file project in the project manager.

2. Add a labeled button in the cell to the right of the Find button.
3. Open the attribute editor for the new button, give it a component ID (`emailButton`), and label the button `Email`.
4. Click the Edit operations button to add behavior to the Email button.
5. Click Insert to add an operation, then click the Action button.

   The default Filter type, Event Filter, is used. There is no need to set the Filter.

6. Choose the action type, Set Attribute.
7. Select `mailDialog` as the target.
8. Select `visible` as the attribute for the Mail dialog box.
9. Open the card file's project`.java` in the source editor.
10. Search for the line:

        public boolean handleMessage(Message msg);

    Add code that closes the dialog box:

         public boolean handleMessage(Message msg) {
            if (msg.name.equals("Send") ||
                msg.name.equals("Cancel")) {
                gui.mailDialog.set("visible", Boolean.FALSE);
                return true;
            } else
                return super.handleMessage(msg);
          }

11. Choose GUI -> Save Generate GUI File to update the `.gui` file for the card file.

To test the application:

1. Click the Build button in the main toolbar.
2. When the build completes, click the Run button in the main toolbar.
3. Click on the Email button in the card file to see if the Mail dialog box opens.
4. Click on the Send or Cancel button in the Mail dialog box to see if the window closes.

See also:

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