Since 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. The constructors for
Dialog
all provide a parent
window (which must be non-null)
and some have an option to set modality:
public Dialog(Frame owner)
public Dialog(Frame owner, boolean modal)
public Dialog(Frame owner, String title)
public Dialog(Frame owner, String title, boolean modal)
There are several more constructors, but this will be enough for us for now.
For example,
Dialog d = new Dialog(someFrame, false);
The modal
argument specifies
whether or not the dialog should be modal. If it should be, pass
true
. If it shouldn't be, pass false
.
There are also some common differences between most frames and most dialogs, but these are not written in stone:
You can make a dialog resizable and movable by calling its 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(parentFrame, "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.