2 つのタイマーが必要です。1 つはゲームを実行するためのものです。たとえば、オブジェクトを動かしたり、チェックを実行したり、もう 1 つはカウントダウン タイマーとして実行したりします。私は次のことを試しました:
Timer countdownTimer = new Timer(1000,this);
Timer gameTimer = new Timer(30,this);
public void init()
{
this.actionPerformed(this); //add action listener to content pane
}
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == gameTimer)
{
// control the game
}
if(e.getSource() == countdownTimer)
{
//decremenet the timer
}
}
ただし、アプレットを実行しようとすると、Null ポインター例外が返されます。各タイマーを他のタイマーと適切に区別し、各タイマーティックで目的のアクションを実行するにはどうすればよいですか。ありがとう