Chapter 17: Windows, Dialogs, Frames, and Menus

The exercises here are taken from my forthcoming book The Java Developer's Resource.

Quiz

  1. What's the difference between a Frame and a Dialog?
  2. What's the difference between a Menu and a MenuBar?
  3. What's the difference between a Menu and a MenuItem?
  4. Why wouldn't you create a Menu inside the MenuBar's add method like you create MenuItem's inside a Menu's add method?

Exercises

  1. It's a little silly to ask the user if they are sure they want to start global thermonuclear war and then only provide an OK button. Write an OK-Cancel Dialog class that produces a modal dialog with two buttons, OK and Cancel. Make the constructor protected. However include a static method that creates a new instance of the OKCancel class and handles user input. This method should take a single String as an argument and return a boolean indicating whether the OK or the Cancel button was pressed. The dialog should dismiss itself when a button is pressed. Make sure a long String is handled reasonably (that is wrap it to fit the box).
  2. Create a subclass of the OKCancel dialog that has buttons for "Yes" and "No" instead.
  3. Revise Program 17.6 so that instead of printing the Menu Choice on System.out it pops up an Alert Dialog from Program 17.3 with the MenuChoice.
  4. Use exercise 1 to revise Program 17.6 so that it asks the user to confirm each menu selection.


[ Exercises | Cafe Au Lait | Books | Trade Shows | Links | FAQ | Tutorial | User Groups ]

Copyright 1996 Elliotte Rusty Harold
elharo@sunsite.unc.edu
Last Modified August 20, 1996