我在尝试编译代码时遇到以下错误:
中的抽象方法
MyClass
不是抽象的,不会覆盖actionPerformed(ActionEvent)
ActionListener
我已经查看了其他帖子和解决方案来处理此错误,但我无法修复它。
这是我的代码:
package NinjaChefGame;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import javax.swing.Timer;
public class Animation extends JPanel implements ActionListener {
Timer tm = new Timer (5,this);
int x = 0, velx = 2;
public void paintComponent (Graphics g) {
super.paintComponent(g);
g.setColor (Color.RED);
g.fillRect(x,30,50,30);
tm.start();
}
public void actionPerfomed(ActionEvent e) {
x = x + velx;
repaint();
}
}
答案 0 :(得分:1)
缺少r
public void actionPerfomed(ActionEvent e)
^^^
public void actionPerformed(ActionEvent e)