Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Timer Restart Java

$
0
0
Hey, i´ve got a problem with my timer.
if i press a button the timer should be reseted.
That works fine, but after i started it twice it goes twice as fast and if i press it three times it goes three times as fast.
How could i make it work properly?
 if(event.getSource() == this.random)
            if (difficulty == "Einfach" || difficulty == "Mittel" || difficulty =="Schwer"){ 
               if (timerzahl == 1){
                   hours =   0;
                   minutes = 0;
                   seconds = 0;
                }
            {TimerTask timerTask = new TimerTask() {
                
                 DecimalFormat df = new DecimalFormat("00");
                 
                
                         
                  @Override
                  public void run() {
                         seconds++;
                         if(seconds > 59){
                             seconds = 0;
                             minutes++;
                         }
                        if(minutes >59){
                            minutes = 0;
                            hours++;
                        }
                        uhr.setText(df.format(hours) + ":" + df.format(minutes)
                        + ":" + df.format(seconds));
                }
               
            };
            timer.schedule(timerTask, new Date(), 1000);
            }
            timerzahl = 1;
        }


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>