Sensing Double Clicking

Sensing that the mouse has been double-clicked requires use of the Event clickCount field. To illustrate this, we've written the DoubleClickApplet program, which is set up like the previous event applets in this chapter. Example 8-3 shows the DoubleClickApplet code.

Example 8-3. DoubleClickApplet Class Listing
 import java.applet.Applet; import java.awt.*; public class DoubleClickApplet extends Applet { public void init() { setLayout(new BorderLayout()); add(new DoubleClickCanvas(), "Center"); } } class DoubleClickCanvas extends Canvas { public boolean mouseDown(Event event, int x, int y) { if(event.clickCount == 2) System.out.println("Double ...

Get Graphic Java™ 1.2, Volume I: AWT, Third 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.