//I use the following code to determine if leftbutton and/or rightbutton 
//down in the Miner gamepublic void mousePressed(MouseEvent e){
 switch(e.getModifiers()){
   case 16:
      leftButtonDown=true;
       break;
   case 4:
      if(leftButtonDown)
            leftRightDown=true;
       else 
            rightButtonDown=true;
       break;
   case 20:
       leftRightDown=true;
       break;
  }
.....

解决方案 »

  1.   

    they are masks.
    public static final int BUTTON1_MASK = 16 
    public static final int BUTTON3_MASK = 4 if both button involed, mask =16+4=20So you also can code like this
    if((e.getModifiers() & InputEvent.BUTTON1_MASK)!=0)
      //left button after 1.4, you can use e.getButton() to determine which button. 
      

  2.   

    if((e.getModifiers() & InputEvent.ALT_MASK) != 0)
      //alt  involved
      

  3.   

    不好意思,我很笨,我上机试了试,没能成功。我的目的是想让我一边按“alt”一边按鼠标时,标签能够显示“ALT”
      

  4.   

    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;public class BtnLabelAction extends Applet {
        Label prompt;
        Button btn;
        public void init()
        {
            setLayout(new BorderLayout());
            prompt=new Label(" Mouse Botton ");
            btn=new Button("OK");
            btn.addMouseListener(new MouseAdapter(){
      public void mousePressed(MouseEvent e){
         if((e.getModifiers() & InputEvent.ALT_MASK) != 0)
    prompt.setText("ALT +  Button"+e.getButton()+" Down");
         else
    prompt.setText("Button "+e.getButton()+" Down");
      }
      public void mouseReleased(MouseEvent e){
         if((e.getModifiers() & InputEvent.ALT_MASK) != 0)
    prompt.setText("ALT +  Button"+e.getButton()+" Up");
         else
    prompt.setText("Button "+e.getButton()+" Up");
      }
    });
            add(prompt,BorderLayout.NORTH);
            add(btn,BorderLayout.SOUTH);       
        }    
    }
      

  5.   

    if (e.getSource()==btn & e.getModifiers()==ActionEvent.ALT_MASK & InputEvent.BUTTON1_MASK)!=0)
    其中&中间要有空格!
      

  6.   

    //..........if((e.getModifiers() & InputEvent.ALT_MASK) != 0)//...........