java 控制台报错:求对报错的解释。 我屏蔽了一条语句:然后就报错了:类不是抽象的且没有覆盖 抽象方法。
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class MouseMove extends Applet implements MouseListener,MouseMotionListener
{
int x,y;
String s = "";
public void init(){
this.addMouseListener(this);
this.addMouseMotionListener(this);
}
public void paint(Graphics g){
g.drawString(s,50,100);
float a,b,c;
a = (float)Math.random();
b = (float)Math.random();
c = (float)Math.random();
g.setColor(new Color(a,b,c));
g.drawString("鼠标当前的位置:("+x+","+y+")",x,y);
}
public void mouseClicked(MouseEvent e){
x = e.getX();
y = e.getY();
if(e.getClickCount()==1)
s="once";
else if(e.getClickCount()==2)
s="twice";
repaint();
}
public void mouseEntered(MouseEvent e){
x = e.getX();
y = e.getY();
s = "鼠标进入Applet";
repaint();
}
public void mouseExited(MouseEvent e){
x = e.getX();
y = e.getY();
s = "鼠标离开了Applet";
repaint();
}
public void mousePressed(MouseEvent e){
x = e.getX();
y = e.getY();
s = "您按下鼠标";
repaint();
}
public void mouseReleased(MouseEvent e){
x = e.getX();
y = e.getY();
s = "您松开了鼠标";
repaint();
}
public void mouseDragged(MouseEvent e){
x = e.getX();
y = e.getY();
s = "您拖动了鼠标";
repaint();
}
/*public void mouseMoved(MouseEvent e){
x = e.getX();
y = e.getY();
s = "您移动了鼠标";
repaint();
}*/
}
追问:恩 抽象类的子类必须实现接口的所有方法吗o我明白 您的意思啦
答案:你的类必须实现MouseListener和MouseMotionListener这两个接口中的所有方法。
所以mouseMoved(MouseEvent e)方法不能被注释掉。
你可以象下面这样注释就没问题了。
public void mouseMoved(MouseEvent e) {
/*
x = e.getX();
y = e.getY();
s = "您移动了鼠标";
repaint();
*/
}
其他:你应该把你的错误贴出来,要不然我怎么解释?
上一个:java多核多线程
下一个:急!用Java实现XML与关系数据类型的互换,求代码!