I have a break timer application. It uses a timer class to keep time and notify me via text message when my break is over. It all works, except it sends me a text message every second once the if statement becomes true. So I got about 60 messages in a minute and it will keep going while it is running. I have tried rewriting the if statement many different ways and it still does the same thing. I know that there is no such thing as if loops but that is what it is doing. the now variable is outside the timer loop, declared in the public class. I post most of the classes code below.
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();
}
}
You need to stop the timer when the first text message is sent. The Timer class has a stop() method for this.