有没有办法在单击鼠标按钮和发布此按钮之间以秒或毫秒为单位。
我使用了这个功能,但不适合我
public void mouseClicked (MouseEvent me) {
long time=me.getWhen();
// other stuff
}
一些帮助?
答案 0 :(得分:1)
它并不适合你,因为getWhen()返回事件发生的时间(以毫秒为单位),而不是事件持续的时间。 这段代码适合我:
long mousePressed;
long mouseReleased;
long mousePressTime;
@Override
public void mousePressed(java.awt.event.MouseEvent e) {
mousePressed = e.getWhen();
}
@Override
public void mouseReleased(java.awt.event.MouseEvent e) {
mouseReleased = e.getWhen();
mousePressTime = mouseReleased - mousePressed;
System.out.println("PRESS TIME "+mousePressTime);
}