Extending MouseAdapter

The application of Figs. 12.3112.32 demonstrates how to determine the number of mouse clicks (i.e., the click count) and how to distinguish between the different mouse buttons. The event listener in this application is an object of inner class MouseClickHandler (Fig. 12.31, lines 25–46) that extends MouseAdapter, so we can declare just the mouseClicked method we need in this example.

 1   // Fig. 12.31: MouseDetailsFrame.java 2   // Demonstrating mouse clicks and distinguishing between mouse buttons. 3   import java.awt.BorderLayout; 4   import java.awt.event.MouseAdapter; 5   import java.awt.event.MouseEvent; 6   import javax.swing.JFrame; 7   import javax.swing.JLabel; 8  9   public class ...

Get Java™ How To Program (Early Objects), Tenth Edition 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.