MichaelG MichaelG - 2 years ago 73
Java Question

What is the best way to check the running status of a Timer?

Desired Output: I would like to check for the running condition of the timer and run some code based on that status.

I have the following code...

if (spin2 == spin3 && timer1.stop()==true)

lblMessage.setText("Congratulations. You matched 2 symbols");
credit = credit + 50;
lblCredit2.setText(credit + " ");
lblCredit2.setForeground(new Color(11,212,0));


However, timer1.stop() == true does not work. I need an alternative...

An Idea:

Is changing the value of a boolean when I call start() or stop() the best way to approach the running condition of a timer? or Is there another solution?

Answer Source


Instead of

timer1.stop()==true //Which isnt even valid because timer.stop doesnt return a boolean


timer1.isRunning(); //It returns a boolean (true or false) if the timer is running or not.

Returns True when timer is Running.

Returns False when timer is not Running.

This would have been a simple fix if you refered to the API.

Heres the Link:


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download