Dialog boxes are top-level windows that depend on another "parent" window. This implies that:
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;
}
}