关于内部类的问题
我在书上看到一个内部类的例子于是我在eclipse中调试了以下,可是例子连编译都没通过,(没有打错),贴出代码让大家指正:
public class TwoListenerInner extends MouseMotionAdapter {
private Frame f;
private TextField tf;
// MouseMotionHandler为一个内部类
public class MouseMotionListener extends MouseMotionAdapter{
public void mouseDragged(MouseEvent e){
String s="Mouse dragging : X="+e.getX()+"Y="+e.getY();
tf.setText(s);
}
}
//MouseEventHandle为一个内部类
public class MouseEventHandler extends MouseAdapter{
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 static void main(String[] args) {
TwoListenerInner that=new TwoListenerInner();
that.go();
}
public void go(){
f=new Frame("Two listeners example");
f.add("North",new Label("Click and drag the mouse"));
tf=new TextField(10);
f.addMouseMotionListener(new MoseMotionHandler());
f.addMouseListener(new MousrEventHandler());
f.setSize(300,200);
f.setVisible(true);
}
}