import java.awt.*;
import java.awt.event.*;
public class TwoListenInner {
private Frame f;
private TextField tf;
public static void main(String args[]) {
TwoListenInner that = new TwoListenInner();
that.go();
}
public void go() {
f = new Frame("Two listeners example");
f.add("North", new Label("Click and drage the mouse"));
tf = new TextField(30);
f.add("South", tf);
f.addMouseMotionListener(new MouseMotionHandler());
f.addMouseMotionListener(new MouseEventHandler());
f.setSize(300, 300);
f.setVisible(true);
}
public class MouseMotionHandler extends MouseMotionAdapter {
public void mouseDragged(MouseEvent e) {
String s = "MouseDragging:X=" + e.getX() + " Y=" + e.getY();
tf.setText(s);
}
}
public class MouseEventHandler extends MouseMotionAdapter {
public void mouseEntered(MouseEvent e) {
String s = "The mouse entered";
tf.setText(s);
}
public void mouseExited(MouseEvent e){
String s="The mouse left the building";
tf.setText(s);}
}
}
我希望达到的效果是:当鼠标进入Frame时文本框提示“The mouse entered”,鼠标在Frame中拖动时显示“MouseDragging:X= Y= ”,鼠标离开时显示“The mouse left the building”.
谁帮我看看是在错在哪里啊?偶是个初学者。。。