鼠标右键事件 [英] Right click mouse event
问题描述
我通过这个论坛进行搜索,但是找不到关于该主题的很好的解释.与以下陈述有何不同?触发该事件的更好方法是哪种方法?
I search through this forum but I can't find a good explanation on this topic. Is there any different from the below statements? Which way is the better way to trigger this event?
if (evt.getButton() == 3)
VS.
if (SwingUtilities.isRightMouseButton(evt))
推荐答案
SwingUtilities.isRightMouseButton(evt)
这使用位操作数进行比较:
this uses a bit operand to compare:
(evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
而其他人,只需将其与可以更改的幻数进行比较,我宁愿将第一个比较更改为:
while other, just compare with a magic number that can change, I would rather change first comparison to:
if(evt.getButton() == java.awt.event.MouseEvent.BUTTON3)
SwingUtilities 是jdk附带的javax的一部分,因此我更愿意将这种责任委派给该实用程序(帮助程序)类,因此在这种情况下, SwingUtilities 胜了.
SwingUtilities is part of the javax which comes with jdk, so I would prefer to delegate that responsabillity to this utility (helper) class, so in that case, SwingUtilities wins.
这篇关于鼠标右键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!