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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.