把TwoListen.java贴出来看看...

解决方案 »

  1.   

    import java.awt.*;
    import java.awt.event.*; public class TwoListen implements 
    MouseMotionListener, MouseListener { 
    private Frame f; 
    private TextField tf; public static void main(String args[]) { 
    TwoListen two = new TwoListen(); 
    two.go(); 

    public void go() { 
    f = new Frame("Two listeners example"); 
    f.add (new Label ("Click and drag the mouse"), "BorderLayout.NORTH");
    tf = new TextField (30); 
    f.add (tf);//, "BorderLayout.SOUTH"); f.addMouseMotionListener(this); 
    f.addMouseListener (this); 
    f.setSize(300, 200); 
    f.setVisible(true); 
    } // These are MouseMotionListener events 
    public void mouseDragged (MouseEvent e) { 
    String s = 
    "Mouse dragging: X = " + e.getX() + " Y = " + e.getY(); 
    tf.setText (s); 

    public void mouseMoved (MouseEvent e) { 
    } // These are MouseListener events 
    public void mouseClicked (MouseEvent e) { 
    } public void mouseEntered (MouseEvent e) { 
    String s = "The mouse entered"; 
    tf.setText (s); 
    }
    public void mouseExited (MouseEvent e) { 
    String s = "The mouse has left the building"; 
    tf.setText (s); 
    } public void mousePressed (MouseEvent e) { 
    } public void mouseReleased (MouseEvent e) { 

    }
      

  2.   


    f.add (new Label ("Click and drag the mouse"), "BorderLayout.NORTH");
    改为
    f.add (new Label ("Click and drag the mouse"), "North");