Java Reference
In-Depth Information
Summary
In this chapter you have learned how to use dialogs to manage data input. You have also learned how to
implement context menus, which can bring a professional feel to the GUI in your applications. You
have applied scrollbars to varying data values as well as scrolling a window, so you should be in a
position to use them in whatever context you need.
The important points we have covered in this chapter are:
A modal dialog blocks input from other windows in the same application as long as it is displayed.
A non-modal dialog does not block input to other windows. You can switch the focus between
a non-modal dialog and other windows in the application whenever necessary.
The JOptionPane class provides static methods for creating simple dialogs.
A pop-up menu is a menu that can be displayed at any point within the coordinate system of a
component.
A context menu is a pop-up menu that is specific to what lies at the point where the menu is
displayed - so the contents of the menu depend on the context.
A context menu is displayed as a result of a pop-up trigger, which is usually a right mouse
button click.
The AffineTransform class defines an affine transformation that can be applied to a
graphics context and to a Shape object.
A Graphic2D object always contains an AffineTransform object, and the default
transform leaves coordinates unchanged.
The transform for a graphics context is applied immediately before user coordinates for a
shape are converted to device coordinates.
There are four kinds of transform you can create: translations, rotations, scaling, and shearing.
You can combine any number of transformations in a single AffineTransform object.
Exercises
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 will display 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.
Search WWH ::




Custom Search