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. ...

Get Java™ Media APIs: Cross-Platform Imaging, Media, and Visualization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.