1

タイマーでエラーが発生するのはなぜですか? コードの下に、エラーの内容が記載されています。何が間違っているのかわかりません....誰か助けてくれますか

       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)
4

3 に答える 3

6

javax.swing.Timerの代わりにインポートする必要がありjava.util.Timerます。

于 2012-05-29T18:33:26.240 に答える
3

をインポートしjava.util.Timerました。を使用しjavax.swing.Timerます。あなたの間違いではありません。

ドキュメントについては、http://docs.oracle.com/javase/7/docs/api/javax/swing/Timer.htmlを参照してください。

于 2012-05-29T18:33:42.617 に答える
-2

次の行の「this」変数:

time = new Timer(5,this);

現在のクラスを参照しており、Timer クラスはそれをどう処理するかを知りません ;)

于 2012-05-29T18:32:09.383 に答える