- The Basic Java 2D Recipe
- Set the Graphics2D Context...
- ...and Render Something
- Rendering on Components
- Shape Primitives
- Graphics Stroking
- Fill Attributes and Painting
- Transparency and Compositing
- Text
- Clipping
- Coordinate Space Transformations
- Techniques for Graphical User Input
- Double Buffering
- Comprehensive Example: Kspace Visualization
- Summary
Techniques for Graphical User Input
Most user interaction problems in 2D consist of determining whether the user clicked on a particular shape or text area and other forms of so-called hit testing. Two methods, Graphics2D.hit() and the Shape.contains(), are particularly useful for solving shape clicking problems. Shape.contains() can be placed in the mouseEvent methods such as mousePressed() and mouseClicked() to test if a particular shape has been selected after the desired mouse event. An example of using the contains() method is provided in Listing 3.3.
Graphics2D.hit() can be used in more or less the same fashion; however, it is necessary to pass the hit() method a rectangular area of device space in which to search for the selected object.