import java.awt.*;
import java.awt.event.*;public class Test{
Frame frame = new Frame("内部类测试!");
TextField tf = new TextField(); Test(){
frame.add(new Label("点击该框架。"),"North");
frame.add(tf,"South");
frame.addMouseMotionListener(new MouseMotionAdapter(){
public void mouseDragged(MouseEvent e){
String s = "该点坐标为( " + e.getX() +" . " + e.getY() + " )";
tf.setText(s);
}
});
frame.setSize(300,300);
frame.setVisible(true);
}
public static void main(String[] args){
Test a = new Test();
}
}为什么我将上面的 frame.addMouseMotionListener(new MouseMotionAdapter(){
换成 frame.addMouseListener(new MouseAdapter(){生成的图形就无法获取鼠标的坐标,我看API文档里面
MouseMotionAdapter和MouseAdapter都继承了MouseMotionListener这个接口,都有 public void mouseDragged(MouseEvent e)这个方法,为什么就有一个是错误的啊。谢谢!
import java.awt.event.*;public class Test{
Frame frame = new Frame("内部类测试!");
TextField tf = new TextField(); Test(){
frame.add(new Label("点击该框架。"),"North");
frame.add(tf,"South");
frame.addMouseMotionListener(new MouseMotionAdapter(){
public void mouseDragged(MouseEvent e){
String s = "该点坐标为( " + e.getX() +" . " + e.getY() + " )";
tf.setText(s);
}
});
frame.setSize(300,300);
frame.setVisible(true);
}
public static void main(String[] args){
Test a = new Test();
}
}为什么我将上面的 frame.addMouseMotionListener(new MouseMotionAdapter(){
换成 frame.addMouseListener(new MouseAdapter(){生成的图形就无法获取鼠标的坐标,我看API文档里面
MouseMotionAdapter和MouseAdapter都继承了MouseMotionListener这个接口,都有 public void mouseDragged(MouseEvent e)这个方法,为什么就有一个是错误的啊。谢谢!
按住鼠标拖下