ブレークタイマーアプリケーションがあります。タイマークラスを使用して時間を維持し、休憩が終わったときにテキストメッセージで通知します。ifステートメントがtrueになると、毎秒テキストメッセージを送信することを除いて、すべて機能します。だから私は1分間に約60のメッセージを受け取り、それが実行されている間それは続きます。ifステートメントをさまざまな方法で書き直してみましたが、それでも同じことを行います。ループのようなものはないことは知っていますが、それがやっているのです。now変数はタイマーループの外側にあり、パブリッククラスで宣言されています。以下にほとんどのクラスコードを投稿します。
private static long now = System.currentTimeMillis();
public BreakTimer() {
this.setText(when());
}
public void actionPerformed(ActionEvent ae) {
(some more code)
long currenttime = System.currentTimeMillis() - now;
int breaknotify = 15 - SettingsIni.breaknotifytime();
if ((currenttime) /6000 == breaknotify){
try {
TextMessage.main(null);
} catch (AddressException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void start() {
BreakTimer.reset();
timer.start();
}
public static void main(String[] args) {
running = true;
BreakTimer jtl = new BreakTimer();
jtl.start();
}
}