可以用MouseEvent的getModifiers()方法,得到的值和InputEvent类的三个常数进行比较
BUTTON3_MASK代表右键,BUTTON1_MASK代表左键

解决方案 »

  1.   

    /*
     A basic extension of the java.applet.Applet class
     */
    import java.awt.*;
    import java.lang.*;
    import java.applet.*;public class DoubleClickApplet extends Applet 
    {
       String mouseClickedString = "Mouse event : none";
       String mouseClickedString2 = "Mouse double click : no";
       long lastDownTime = 0;
       final static long DOUBLE_CLICK_TIME = 500;
       public boolean mouseDown(Event evt, int x, int y) 
       {
          if((evt.when - lastDownTime) < DOUBLE_CLICK_TIME) 
             mouseDoubleClick(evt, x, y);
          else 
          {
             mouseClickedString2 = "Mouse double click : no";
             repaint();
          }
          lastDownTime = evt.when;
          mouseClickedString = "Mouse event : mouseDown";
          getAppletContext().showStatus("Mouse Click");
          repaint();
          return false;
       }
       public boolean mouseDoubleClick(Event evt, int x, int y) 
       {
          mouseClickedString2 = "Mouse double click : yes";
          getAppletContext().showStatus("Mouse Double Click");
          repaint();
          return false;
       }
       public boolean mouseDrag(Event evt, int x, int y) 
       {
          mouseClickedString = "Mouse event : mouseDrag";
          getAppletContext().showStatus("Mouse Drag");
          repaint();
          return false;
       }
       public boolean mouseEnter(Event evt, int x, int y) 
       {
          mouseClickedString = "Mouse event : mouseEnter";
          getAppletContext().showStatus("Mouse Enter");
          repaint();
          return false;
       }
       public boolean mouseExit(Event evt, int x, int y) 
       {
          mouseClickedString = "Mouse event : mouseExit";
          getAppletContext().showStatus("Mouse Exit");
          repaint();
          return false;
       }
       public boolean mouseUp(Event evt, int x, int y) 
       {
          mouseClickedString = "Mouse event : mouseUp";
          getAppletContext().showStatus("Mouse Up");
          repaint();
          return false;
       }
       //  public boolean mouseMove(Event evt,int x,int y)
       //  {
       //    mouseClickedString="Mouse event : mouseMove";
       //    mouseClickedString2="Mouse double click : no";
       //    repaint();
       //    return false;
       //  }
       public void paint(Graphics g) 
       {
          g.drawString(mouseClickedString, 20, 20);
          g.drawString(mouseClickedString2, 20, 50);
       }
    }