用MouseListener
public void mouseClicked(MouseEvent e){
  if(e.getClickCount()==2){//鼠标双击
        //TODO
    }
}

解决方案 »

  1.   

    kypfos(我不是深圳人) 说对了
      

  2.   

    具体怎么写啊??
    怎样用MouseListener?
    能把具体的程序写出来吗?
    谢谢~
      

  3.   

    import java.awt.*;
    import java.awt.event.*;
    import javabook.*;
    class testmouseframe 
    {
    public static void main(String[] args) 
    {
    menuframe frame=new menuframe();
            frame.start();
    }
    }
    class menuframe extends Frame implements MouseListener,WindowListener
    {
      private static final int FRAMEWIDTH=450;
      private static final int FRAMEHEIGHT=300;
      private static final int FRAME_X=50;
      private static final int FRAME_Y=50;
      private OutputBox outputbox;
     
      public menuframe()
    {
         setSize(FRAMEWIDTH,FRAMEHEIGHT);
     setResizable(false);
     setTitle("TrackMouseFrame");
     setLocation(FRAME_X,FRAME_Y);
         outputbox=new OutputBox(this);     addMouseListener(this);
     addWindowListener(new ProgramTerminator());
      }
      public void start()
    {
         setVisible(true);
     outputbox.setVisible(true);
      }
      
      public void windowClosing(WindowEvent event)
    {System.exit(0);}
      public void windowActivated(WindowEvent event){}
      public void windowClosed(WindowEvent event){}
      public void windowOpened(WindowEvent event){}
      public void windowDeactivated(WindowEvent event){}
      public void windowDeiconified(WindowEvent event){}
      public void windowIconified(WindowEvent event){}  public void mouseClicked(MouseEvent event)
    {
      if (event.getClickCount()==2)
      {
            outputbox.clear();
      }
      else{
         int x,y;
     x=event.getX();
     y=event.getY();
     outputbox.println("["+x+","+y+"]");}
      }
       public void mouseEntered(MouseEvent event){}
       public void mouseExited(MouseEvent event){}
       public void mousePressed(MouseEvent event){}
       public void mouseReleased(MouseEvent event){}
    }
    class ProgramTerminator implements WindowListener
      {
      public void windowClosing(WindowEvent event)
    {System.exit(0);}
      public void windowActivated(WindowEvent event){}
      public void windowClosed(WindowEvent event){}
      public void windowOpened(WindowEvent event){}
      public void windowDeactivated(WindowEvent event){}
      public void windowDeiconified(WindowEvent event){}
      public void windowIconified(WindowEvent event){}
      } 
    看看这段代码,你就明白了:)
      

  4.   

    public class MainFrame extends java.awt.Frame
    {
      public MainFrame()
      {
       addMouseListener(new java.awt.event.MouseAdapter()
       {
         public void mouseClicked(java.awt.event.MouseEvent e)
         {
           if(e.clickCount==2){
              //TODO: todo something
           }
         }
       });
       show();
      }
    }