Checking modifiers to MouseEvent

From: Luc Van Bogaert (luc.van.bogaert.invalid_at_skynet.be)
Date: 11/29/03


Date: Sat, 29 Nov 2003 11:53:55 +0100

Hi,

Here's a piece of code that's in the online Java API documentation, but
it doesn't compile because of a type mismatch (boolean <-> int)

===============
"It is not recommended to compare the return value of this method using
== because new modifiers can be added in the future. For example, the
appropriate way to check that SHIFT and BUTTON1 are down, but CTRL is up
is demonstrated by the following code:

     int onmask = SHIFT_DOWN_MASK | BUTTON1_DOWN_MASK;
     int offmask = CTRL_DOWN_MASK;
     if (event.getModifiersEx() & (onmask | offmask) == onmask) {
         ...
     }

The above code will work even if new modifiers are added."
===============

Could someone help in turning this into a workable piece of code so I
can check in MousePressed, wether MB1, MB2 or both are down?

Thanks.

-- 
Luc Van Bogaert

Quantcast