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:

  1. A frame can have a menu bar. A dialog cannot.
  2. A dialog can be modal. A frame cannot.
  3. A dialog has a parent frame. A frame does not. When the parent frame is closed so is the dialog.

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.

Previous | Next | Top | Cafe au Lait

Copyright 1997, 2002, 2005 Elliotte Rusty Harold
Last Modified July 1, 2005