程序代码:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class dbclick extends Applet implements MouseListener
{
boolean isDoubleClick = false; // 是否双击标志
public void init()
{
addMouseListener(this); // 进行鼠标事件监听
}
public void paint(Graphics g)
{
g.drawString("请单击或双击鼠标", 10,10);
if(isDoubleClick)
g.drawString("您双击了鼠标",10,30);
else
g.drawString(" ",10,30); // 清除显示双击信息
}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseClicked(MouseEvent e)
{
isDoubleClick = e.getClickCount() == 2; // 连续击打次数为2,则说明是双击了鼠标
repaint();
}
}
说明:所谓双击,其实就是判断了连续击打鼠标键的次数,您可以把次数改成3,4,5...试试看:),还有,在以前的JDK中,具体版本不知道,是没有getClickCount()函数的,可以用两次点击鼠标键的时间间隔来判断是否在指定的范围内.其实原理就是这样.