为什么我在计时器中出错?在代码下面说明错误是什么。我无法弄清楚什么即时做错了....谁能帮我有人可以解释为什么我得到这个错误与计时器?
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)
阅读文档。 – asawyer
正如错误状态一样;没有'Timer' ctor需要'Board'参数。 –
是的,我使用了错误的定时器 –