Chapter 17: Windows, Dialogs, Frames, and Menus
The exercises here are taken from my forthcoming book
The Java Developer's Resource.
Quiz
- What's the difference between a Frame and a Dialog?
- What's the difference between a Menu and a MenuBar?
- What's the difference between a Menu and a MenuItem?
- 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
- 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).
- Create a subclass of the OKCancel dialog that has buttons for "Yes" and "No" instead.
- 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.
- 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