增加鼠标事件,如鼠标压下等地那个

解决方案 »

  1.   

    import java.awt.*;
    import java.awt.event.*;
    public class Example18_6 extends Applet implements MouseMotionListener
    { TextField text;
     public void init()
     { text=new TextField();
       setLayout(new BorderLayout());
       setBackground(Color.green);
       addMouseMotionListener(this); add(text,"South");
     }
     public void mouseDragged(MouseEvent e)
     {text.setBackground(Color.red); 
      text.setText("鼠标的坐标:"+"("+e.getX()+","+e.getY()+")");
     }
     public void mouseMoved(MouseEvent e)
     {text.setBackground(Color.blue);
      text.setText("鼠标的坐标:"+"("+e.getX()+","+e.getY()+")");
     } 
    }