Sun Java Solaris Communities My SDN Account Join SDN
 
Tutorials & Code Camps

OK Dialog

 

Training Index



by jGuru

Help  API Docs  About This Short Course  Short Course  Exercises

Create and open a dialog box that waits for the user to hit the "OK" button before it disappears and the applet finishes. Have the applet add the label "Back from dialog..." to its display when the OK dialog has returned. Hide and dispose of the dialog box right before adding the label.

Skeleton Code

Tasks

1. Create an applet with an init() method that makes a dummy Frame (because dialogs can only be "children" of frames) and then creates an OKDialog and shows the dialog. (OKDialog is defined in the next task.)
2. Create OKDialog as a subclass of BlockingDialog (provided for you). It should add the label "Hit the button..." followed by an "OK" button. Use a FlowLayout object for geometry management and resize it to 100 x 100.
3. In the applet's init() method:
  1. Call waitForResponse() (a blocking method) on the dialog right after showing it
  2. When the dialog (that is, waitForResponse()) returns, add the label "Back from dialog..." to the applet
  3. Dispose of the dialog

Where help exists, the task numbers above are linked to the step-by-step help page.

Solution Source

Demonstration

This exercise only runs within browsers that support the Java Runtime Environment 1.1 and appletviewer. If you are using an appropriate browser, try this exercise. The output should look similar to the following:

OKDIALOG.GIF

A dialog box should appear outside of the browser. If this does not occur, your browser does not handle dialog boxes properly.

Next Exercise

Exercises

Short Course

Copyright 1996-2000 jGuru.com. All Rights Reserved.