Java Reference
In-Depth Information
bars to varying data values as well as scrolled a window, so you should be in a position to use them in
whatever context you need.
There are many more components in the Swing library classes than I have the space to discuss in the
book, but if you have managed to get Sketcher working with all the features of this chapter, you should have
no difficulty working with other Swing components.
EXERCISES
You can download the source code for the examples in the topic and the solutions to the following exer-
cises from www.wrox.com .
1. Implement a dialog initiated from a toolbar button to select the current element color.
2. Add a menu item to the Element context menu that displays information about the element at the
cursor in a dialog — what it is and its basic defining data.
3. Display a special context menu when the cursor is over a TEXT object that provides a menu option
to edit the text through a dialog.
4. Change the implementations of the element classes to make use of the combined translate and rotate
operation.
5. Add a toolbar button to switch highlighting on and off. The same button should turn it on when it is
off and vice versa, so you need to change the button label appropriately.
6. Add a Scale menu item to the element context menu that allows a geometric element to be scaled
by dragging the mouse cursor.
7. Implement a main menu item and a toolbar button for choosing a custom color.
• WHAT YOU LEARNED IN THIS CHAPTER
TOPIC
CONCEPT
Modal Dia-
logs
A modal dialog blocks input from other windows in the same application as long as it is displayed.
Modeless
Dialogs
A modeless dialog does not block input to other windows. You can switch the focus between a modeless
dialog and other windows in the application whenever necessary.
Status Bars A status bar can appear at the bottom of an application window and displays application parameter val-
ues of interest to the user. You can define a class to represent a status bar very easily.
The JOp-
tionPane
class
The JOptionPane class provides static methods for creating simple dialogs.
Pop-up
Menus
A pop-up menu is a menu that can be displayed at any point within the coordinate system of a compon-
ent.
Context
Menus
A context menu is a pop-up menu that varies depending on what lies at the point where the menu is dis-
played — so the contents of the menu depend on the context.
Pop-up Trig-
ger
A context menu is displayed as a result of a pop-up trigger, which is usually a left mouse-button click for
a right-handed mouse setup.
Search WWH ::




Custom Search