Dialog
and Frame
are both subclasses of Window
, they share many methods
including setLocation()
and setSize()
.
The only methods that are significantly different between a dialog and a frame are the constructors. There are two constructors for Dialog
which differ in whether or not the dialog is given a title. This titleless constructor is
Dialog d = new Dialog(new Frame(), false);
The second argument is a boolean
which specifies whether or not the dialog should be modal. If it should be, pass true
. If it shouldn't be, pass false
. Modal dialogs are only modal relative to their parent frame, which is passed as the first argument to the constructor.
That is they block input to the parent frame but not to other frames.
Can you pass null
instead of a new Frame?
If you create the parent frame one right inside the constructor as done here, the dialog cannot be truly modal.
There are also some common differences between most frames and most dialogs, but these are not written in stone:
setResizable()
method with a boolean value of true
like this:
d.setResizable(true);
You can give a dialog a title bar by adding the title string to the constructor:
Dialog d = new Dialog(new Frame(), "My Dialog Window", false);
All the other methods of the Dialog
class are exactly the same as they are for Frame
s. You resize them the same way. You move them the same way. You make them visible the same way. You add components to them the same way.