When creating a Java GUI, it is often the case that you want some action to be taken when the user double-clicks on some component. Although there is no simple way to detect double-clicks in Java 1.0.2, the new 1.1 event model provides an easy way to do this. Simply call the getClickCount() method on the instance of the MouseEvent class that is passed to the mouseClicked() or mousePressed() methods which are part of the MouseListener interface. When a value of 2 is returned from getClickCount(), this indicates that the user has double-clicked on the component. For example:
import java.awt.*;import java.awt.event.*;public class DoubleClickTest extends Panel implements MouseListener { public void mousePressed(MouseEvent event) { if (event.getClickCount() == 2) { // Executed only when the user double-clicks onthis component System.out.println("User double-clicked"); } // if (event.getClickCount() == 2) } // public void mousePressed() public void mouseReleased(MouseEvent event) {}; public void mouseEntered(MouseEvent event) {}; public void mouseExited(MouseEvent event) {}; public void mouseClicked(MouseEvent event) {};} // public class DoubleClickTest extends Panel implements MouseListener()