Frames are useful for windows that will stick around for awhile,
some text that's being edited for instance. Dialogs
are more transitory. They're used for simple user input or for
quick alerts to the user.
Like java.awt.Frame
, java.awt.Dialog
is a subclass of java.awt.Window
and hence of
java.awt.Container
and java.awt.Component
.
Therefore a lot of what you learned about frames applies to dialogs
as well. You move them, resize them and add to them almost exactly
as you do frames. There are three main differences between dialogs and
frames:
Menu bars are covered next class. Right now let's talk about modal versus non-modal dialogs. A modal dialog blocks all other use of the application until the user responds to it. A modal dialog cannot be moved and does not allow the user to switch to another window in the same program. On some platforms the user may not even be able to switch to another program.
In the 1970's a computer virus worked its way into several early timesharing systems. The computer program would periodically break in on a user's session and say "I WANT A COOKIE." The terminal would then refuse to respond to any user input until the user typed the word "COOKIE" at which point the program would say something like "MMM, MMM, THAT WAS GOOD." and return control to the user.
Modal dialogs are a lot like the cookie monster program. They request input from the user and don't let anything else happen until they get it. Non-modal dialogs pop-up but they don't prevent the user from doing other things while they're visible. Because modal dialogs inconvenience users by forcing them to respond when the computer wants them to rather than when they want to, their use should be kept to a minimum.