... yPos = event.getY(); // get y-position of mouse
33
34            details = String.format("Clicked %d time(s)",
35               event.getClickCount());
36
37            if (event.isMetaDown()) // right mouse button
38               details += " with right mouse button";
39            else if (event.isAltDown()) // middle mouse button
40               details += " with center mouse button";
41            else // left mouse button
42               details += " with left mouse button";
43
44            statusBar.setText(details); // display message in statusBar
45         }
46      }
47   }

Fig. 26.32 Testing MouseDetailsFrame.

 1   // Fig. 26.32: MouseDetails.java
 2   // Testing MouseDetailsFrame.
 3   import javax.swing.JFrame;
 4
 5   public class MouseDetails
 6   {
 7      public static void main(String[] args)
 8      {
 9         MouseDetailsFrame mouseDetailsFrame = new MouseDetailsFrame();

Get Java How to Program, Early Objects, 11th 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.