1

ここにコードがあります

public class TimeClass implements ActionListener{
    int timerCounter;

    public TimeClass(int timerCounter){
        this.timerCounter = timerCounter; 
    }

    public void ActionPerformed(ActionEvent time){

        timerCounter--;
        if(timerCounter >= 1){
        timeLeft.setText("Time Remaining: " + timerCounter);    
        }else{

            timer.stop();
            timeLeft.setText("Game Over!");
            click.setEnabled(false);    
        }
    }
    public void actionPerformed(ActionEvent e) {    
    }   
    }

タイマーがデクリメントしません。コードのどこが間違っていますか?プレゼンテーションにこれが必要です。できるだけ早くこれが必要です。ありがとう。

4

1 に答える 1

1

間違ったメソッドで機能を実装しました。次の場所にあるはずですactionPerformed:

@Override public void actionPerformed(ActionEvent time){

    timerCounter--;
    if(timerCounter >= 1){
    timeLeft.setText("Time Remaining: " + timerCounter);    
    }else{

        timer.stop();
        timeLeft.setText("Game Over!");
        click.setEnabled(false);    
    }
}

メソッドをオーバーライドするときに表記法を使用する@Overrideと、上書きしないメソッドで使用するとコンパイラが警告するため、このような間違いを避けるのに役立ちます。

于 2013-03-24T10:51:19.080 に答える