Java 有人能解释一下为什么我的计时器出现了这个错误吗?

Java 有人能解释一下为什么我的计时器出现了这个错误吗?,java,swing,timer,Java,Swing,Timer,为什么计时器会出错?在代码下面,它说明了错误是什么。我不知道我做错了什么。。。。有人能帮我吗 import java.util.Timer; import javax.swing.ImageIcon; import javax.swing.JPanel; /** * * @author Rich */ public class Board extends JPanel implements

为什么计时器会出错?在代码下面,它说明了错误是什么。我不知道我做错了什么。。。。有人能帮我吗

       import java.util.Timer;
       import javax.swing.ImageIcon;
       import javax.swing.JPanel;

       /**
        *
      * @author Rich
      */
     public class Board extends JPanel implements ActionListener{
         Dude p;
        Image img;
       Timer time;

        public Board() {
         p = new Dude();
        addKeyListener(new AL());
         setFocusable(true);
          ImageIcon i = new ImageIcon("images.jpg");
          img = i.getImage();
          time = new Timer(5,this);
          time.start();
        }

        public void actionPerformed(ActionEvent e) {
        p.move();
        repaint();
         }
基本上我得到的错误是

no  suitable constructor found for Timer(int,OurGame.Board)
constructor java.util.Timer.Timer(java.lang.String,boolean) is not applicable
  (actual argument int cannot be converted to java.lang.String by method invocation conversion)
constructor java.util.Timer.Timer(java.lang.String) is not applicable
  (actual and formal argument lists differ in length)
constructor java.util.Timer.Timer(boolean) is not applicable
  (actual and formal argument lists differ in length)
constructor java.util.Timer.Timer() is not applicable
  (actual and formal argument lists differ in length)

下一行中的“this”变量:

time = new Timer(5,this);

引用当前类,而Timer类不知道如何处理它;)

下一行中的“this”变量:

time = new Timer(5,this);

引用当前类,而Timer类不知道如何处理它;)

您应该导入
javax.swing.Timer
而不是
java.util.Timer

您应该导入
javax.swing.Timer
而不是
java.util.Timer

您导入的
java.util.Timer
。使用
javax.swing.Timer
。 不是你的错,你经常看到


对于文档,请阅读。

您导入的
java.util.Timer
。使用
javax.swing.Timer
。 不是你的错,你经常看到


对于文档,请完全按照错误状态阅读。

;没有
计时器
接受
参数的ctor。是的,错误状态下我使用了错误的计时器;没有
Timer
ctor接受
Board
参数。是的,我使用了错误的Timer错误,他的类实现了ActionListener,因此它是一个有效的参数。首先阅读文档,或者自己试试。非常错误,他的类实现了ActionListener,所以它是一个有效的参数。先阅读文档,或者自己试试。