Dialog Boxes

Dialog boxes are top-level windows that depend on another "parent" window. This implies that:

A dialog box can be modal: all interaction with other windows (of the applet) is blocked until the dialog is completed by calling hide() (JDK 1.0.2) or setVisible(false) (JDK 1.1).
By default a dialog box is not modal.

An applet has no access to "its" window, so it cannot create a dialog box. But an applet can create independent windows (frames) which can create dialog boxes.

Example:

Some of the source for this applet is:

class SimpleDialog extends Dialog {
    TextField field;
    DialogWindow parent;
    Button setButton;

    SimpleDialog(Frame dw, String title) {
        super(dw, title, false);
        parent = (DialogWindow)dw;

        //Create middle section.
        Panel p1 = new Panel();
        Label label = new Label("Enter random text here:");
        p1.add(label);
        field = new TextField(40);
        p1.add(field);
        add("Center", p1);

        //Create bottom row.
        Panel p2 = new Panel();
        p2.setLayout(new FlowLayout(FlowLayout.RIGHT));
        Button b = new Button("Cancel");
        setButton = new Button("Set");
        p2.add(b);
        p2.add(setButton);
        add("South", p2);

        //Initialize this dialog to its preferred size.
        pack();
    }

    public boolean action(Event event, Object arg) {
        if ( (event.target == setButton)
           | (event.target == field)) {
            parent.setText(field.getText());
        }
        field.selectAll();
        hide();
        return true;
    }
}