私はJavaを初めて使用し(約1週間しか使用していません)、ストアシミュレーターに取り組んでいます。基本的には、画面に表示されている変数を閉じるまでの時間や開いてからの時間など、今すぐ基本的なことをやりたいと思っています。
シミュレーションで次の関数を作成し、javax.swing.JFrameクラスを拡張しました。
public void incOpenTime() {
timeOpen++;
int hours = timeOpen / 3600;
int minutes = (timeOpen % 3600) / 60;
int seconds = (timeOpen % 3600) % 60;
this.openTime.setText((hours < 10 ? "0" : "") + hours
+ ":" + (minutes < 10 ? "0" : "") + minutes
+ ":" + (seconds < 10 ? "0" : "") + seconds);
decTimeLeft();
}
public void decTimeLeft() {
int remainingTime = 28800 - timeOpen;
int hours = remainingTime / 3600;
int minutes = (remainingTime % 3600) / 60;
int seconds = (remainingTime % 3600) % 60;
this.timeLeft.setText((hours < 10 ? "0" : "") + hours
+ ":" + (minutes < 10 ? "0" : "") + minutes
+ ":" + (seconds < 10 ? "0" : "") + seconds);
}
setText()メソッドを使用するopenTime変数とtimeLeft変数は、GUI自体の一部です。
主に、私は次のようにincOpenTimeを呼び出します。
while(this.timeOpen < 28800)
{
incOpenTime();
}
まず、これを実行すると、基本的にループを通過し、最後にのみ画面に出力されます。時代が絶えず変化するようにするにはどうすればよいですか?
次に、少し遅らせたいと思います...おそらく1秒あたり約1ミリ秒なので、シミュレーションの実行速度が遅くなり、画面に出力される他のデータ(後で)が読みやすくなります。Thread.sleep(1);を試しました。ループ内にありますが、変更された番号は表示されません。
助けてください。
ありがとう
編集:
これが私がそれを機能させるためにしたことです。主に:
timer = new Timer();
for(int i=1; i<= 28800; i++)
{
timer.schedule(new task(), 1*i);
}
新しいクラスを作成しました:
class task extends TimerTask {
@Override
public void run() {
incOpenTime();
}
}