永发信息网

我这java带码那里错了

答案:2  悬赏:10  手机版
解决时间 2021-05-17 12:17
  • 提问者网友:玫瑰园
  • 2021-05-16 13:59

import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
public class TestMultiListener implements
MouseMotionListener,MouseListener {
Frame f =new Frame("多重监听哭测试");
TextField tf=new TextField(30);

public TestMultiListener(){
Label guide=new Label("请按下鼠标左键并拖动");
f.add(guide,"Noth");
f.add(tf,"South");
f.setBackground(new Color(180,225,225));
f.addMouseMotionListener(this);
f.addMouseListener(this);
f.setSize(300,200);
f.setVisible(true);
}
public static void main(String[] args) {
TestMultiListener t=new TestMultiListener();
}
public void mouseDargged(MouseEvent e){
String s="鼠标拖动到位置("+e.getX()+
","+e.getY()+")";
tf.setText(s);
}
public void mouseEntered(MouseEvent e){
tf.setText("鼠标已进入窗体");
}
public void mouseExited(MouseEvent e){
tf.setText("鼠标已移出窗体");
}
public void mouseMoved(MouseEvent e){}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
}

最佳答案
  • 五星知识达人网友:鸽屿
  • 2021-05-16 15:00

下面加两个接口要实现的方法


public void mouseDragged(MouseEvent arg0) {}


public void mouseClicked(MouseEvent arg0) {}


然后你的north拼错了


public TestMultiListener(){
Label guide=new Label("请按下鼠标左键并拖动");
f.add(guide,"North");
f.add(tf,"South");


全部回答
  • 1楼网友:酒者煙囻
  • 2021-05-16 15:59

您的程序缺了两个method:

public void mouseDragged(MouseEvent arg0) {

// TODO Auto-generated method stub

}

public void mouseClicked(MouseEvent arg0) {

// TODO Auto-generated method stub

}

因为 implements MouseMotionListener,MouseListener

就必须要有这两个method的implementation.

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯