A quick way to find out if a user made a doubleclick with their mouse is to implement a MouseListener in the application and add this in your MouseClicked() method
GeSHi (java):
doubleClicked = doubleClicked+1;
if(doubleClicked ==2){
System.
out.
println("double clicked");
doubleClicked = 0;
}
Created by GeSHI 1.0.7.20
However, this will always register the 2nd click as the doubleclick and you don't want that, i've rewritten my code so that the doubleclick only shows up when the mouse is in the same position as before and the user has clicked twice within the same position.
GeSHi (java):
/*--------------------------------------------------------------------------
MouseDoubleClick class
*****************
By: deAppel http://www.engineeringserver.com - http://www.javaforums.net
Contact: info [@] engineeringserver.com
Version: 11/August/2008
Last updated: 11/August/2008
*****************
Note: MouseDoubleClick demo
//----------------------------------------------------------------------*/
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
int doubleClicked = 0;
int positionX = 0;
int positionY = 0;
public MouseDoubleClick (){
addMouseListener(this);
setTitle("Mouse doubleclick demo");
setLocationRelativeTo(null);
setSize(200,200);
setVisible(true);
}
public static void main
(String[] args
){ new MouseDoubleClick();
}
doubleClicked = doubleClicked+1;
if(doubleClicked ==2 && positionX == e.getX() && positionY == e.getY()){
System.
out.
println("double clicked");
doubleClicked = 0;
}
if(doubleClicked > 2){
doubleClicked = 0;
}
positionX = e.getX();
positionY = e.getY();
}
}
Created by GeSHI 1.0.7.20