YesNo and ModalYesNo

A Dialog is essentially just a top level window. The useful thing about a Dialog is that it can be made "modal". When a Dialog is modal, it seizes control of all user input until it is dispose()ed of. Often this is used for prompting the user with an important question or forcing an acknowledgement of some action.

There are now two examples here: YesNo is a non-modal Dialog, ModalYesNo is only slightly different, but shows how to make the dialog modal. The ModalYesNo example has an additional button in the "main application". You shouldn't be able to use the button until you have answered the dialog's question.

Both examples can be run as stand-alone applications:

        java YesNo
and
        java ModalYesNo

Note: There is an error in the printed version of this example. In the book, YesNo is constructed modal; as it is written it will not work unless it is non-modal. As in the FileDialog example of chapter 10, the show() method of a modal dialog blocks until the dialog has been dispose()ed of. A modal Dialog makes things a little easier because we don't have to go to the trouble of performing the wait() and notify() which accomplish the waiting in the answer() method of our non-modal example. ModalYesNo illustrates this.