java 鼠标事件处理方法_关于java鼠标事件处理的一个问题

如果你的输出结果是:

点击鼠标

鼠标单击了两次

那么可能是以下原因:鼠标每次单击都会产生 mouseClicked 事件,但第一次产生时,clickCount 不是2而是1,此时会输出 else 语句。

详细情况请看:

if the first mouse button is pressed, events are sent in the following order:

id modifiers button

MOUSE_PRESSED: BUTTON1_MASK BUTTON1

MOUSE_RELEASED: BUTTON1_MASK BUTTON1

MOUSE_CLICKED: BUTTON1_MASK BUTTON1

When multiple mouse buttons are pressed, each press, release, and click results in a separate event.

For example, if the user presses button 1 followed by button 2, and then releases them in the same order, the following sequence of events is generated:

id modifiers button

MOUSE_PRESSED: BUTTON1_MASK BUTTON1

MOUSE_PRESSED: BUTTON2_MASK BUTTON2

MOUSE_RELEASED: BUTTON1_MASK BUTTON1

MOUSE_CLICKED: BUTTON1_MASK BUTTON1

MOUSE_RELEASED: BUTTON2_MASK BUTTON2

MOUSE_CLICKED: BUTTON2_MASK BUTTON2

If button 2 is released first, the MOUSE_RELEASED/MOUSE_CLICKED pair for BUTTON2_MASK arrives first, followed by the pair for BUTTON1_MASK.参考来自:

http://download.oracle.com/javase/1.4.2/docs/api/java/awt/event/MouseEvent.html#getClickCount()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值