• Post Reply Bookmark Topic Watch Topic
  • New Topic

help with Java timer  RSS feed

 
Jamie Swanson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have been working on a stopwatch/timer program.
everything works good except my timer, when counting down, goes negative.
any ideas?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello "Me AndYou".
Welcome to the Ranch. We are happy to have you here

On your way in, looks like you missed out on our naming policy. Could you please adjust your screen name to comply to the same? You can do it by clicking here.

Coming back to your question.
You really need to tell the details. That will help others help you better.
 
Jamie Swanson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Thanks for the suggestions.
Like I said, I was trying to make a stopwatch/timer program. The stopwatch works well, there are no problems with that. With the timer, I am using the same logic and a copy of the same actionPerformed method. It seems to be working but it seems to be going negative. Meaning if I start the timer from 0:01:00:0 (hour:minutes:seconds:microseconds) the display I get would read 0:01:0 : . And it will go on until basically all the digits disappear. I have my code below:



CountDownListener cd = new CountDownListener();
T = new Timer(100, cd);
millisecondLED.negativeMutate();
T.start();

private class CountDownListener implements ActionListener {

// The ActionListener that is fired by the Timer
public void actionPerformed(ActionEvent e)
{
millisecondLED.negativeMutate();
repaint(); // This method call requests that the graphics be redrawn
// See what happens if it is not done.

int milliactive = millisecondLED.getActive();
if (milliactive == 0) {

onesecondLED.negativeMutate();
repaint();

int oneSecActive = onesecondLED.getActive();
if (oneSecActive == 0){
tensecondLED.negativeMutate();
repaint();

int tenSecActive = tensecondLED.getActive();
if (tenSecActive == 6){
onesminuteLED.negativeMutate();
repaint();
tensecondLED.setActive(0);

int oneMinActive = onesminuteLED.getActive();
if (oneMinActive == 0){
tensminuteLED.negativeMutate();
repaint();

int tenMinActive = tensminuteLED.getActive();
if (tenMinActive == 6){
hourLED.negativeMutate();
repaint();
tensminuteLED.setActive(0);
}
}
}
}
}
}

}

public void negativeMutate()
{
active = (active - 1) % 10;
}


private int active;

public Digits(int X, int Y, int sz)
{
super(X, Y, sz);
active = 0;
}

public int getActive() {
return active;
}

public void setActive(int active) {
this.active = active;
}
 
Jamie Swanson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry,
Please disregard any comments I wrote in the code to myself.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!