Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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))
like image 472
searchfunction Avatar asked Nov 28 '25 18:11

searchfunction


1 Answers

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 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.

like image 107
RamonBoza Avatar answered Nov 30 '25 08:11

RamonBoza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!