[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: how to determine the event when the left mouse button AND the right mouse button click at the same time

i know what it mean now , i just not familiar with the bit shift operation. 
the following code is my solution:
-------------------------------------------
  label.addMouseListener(new MouseAdapter() {
   int buttons = 0;
   private boolean leftdown;
   private boolean rightdown;

   public void mouseUp(MouseEvent e) {
    // buttons &= ~(1 << (e.button - 1));
    // System.out.println("UP: " + e);

    if (e.button == 1) {
     leftdown = false;
    }

    if (e.button == 3) {
     rightdown = false;
    }

   }

   public void mouseDown(MouseEvent e) {

    if (e.button == 1) {
     leftdown = true;
    }

    if (e.button == 3) {
     rightdown = true;
    }

    if (leftdown && rightdown) {
     System.out.println("left+right is down");
    }

    // buttons |= 1 << (e.button - 1);
    // if (buttons == 5 /* binary 00000101 */)
    // System.out.println("left+right is down");
    // System.out.println("DOWN: " + e);
   }

  });
-------------------------------------------
----- Original Message ----- 
From: "Shuai Yang" <yangshuai@xxxxxxxxx>
Newsgroups: eclipse.platform.swt
Sent: Thursday, June 12, 2008 2:06 PM
Subject: Re: how to determine the event when the left mouse button AND the 
right mouse button click at the same time


> hi viliam, your solution really works, but can you explain it, i just know 
> the grammer, but don't know the meaning. thanks!
> "Viliam Durina" <viliam.durina@xxxxxxxxx> 
> ??????:g2nngk$68m$1@xxxxxxxxxxxxxxxxxxxx
>> You probably have to track which buttons were clicked manually:
>>
>> label.addMouseListener(new MouseAdapter() {
>> int buttons = 0;
>>
>> public void mouseUp(MouseEvent e) {
>> buttons &= ~(1 << (e.button-1));
>> }
>>
>> public void mouseDown(MouseEvent e) {
>> buttons |= 1 << (e.button-1);
>> if (buttons == 5 /* binary 00000101*/)
>> System.out.println("left+right is down");
>> }
>>
>> });
>>
>>
>> Viliam
>>
>>
>> Shuai Yang  wrote / napísal(a):
>>> hi all,
>>> i want to know how to determine the event when the left mouse button AND 
>>> the right mouse button click at the same time. i want to write a 
>>> minesweeper game, as you know you can click the left and the right mouse 
>>> button at the same time to open the cells that is not a mine in 
>>> microsoft minesweeper. i just want to know how to determine this event.
>>> thanks.
>>>
>