programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Paul Clapham
• Ron McLeod
• Tim Cooke
• Junilu Lacar
Sheriffs:
• Rob Spoor
• Devaka Cooray
• Jeanne Boyarsky
Saloon Keepers:
• Jesse Silverman
• Stephan van Hulst
• Tim Moores
• Carey Brown
• Tim Holloway
Bartenders:
• Jj Roberts
• Al Hobbs
• Piet Souris

# Need a variable that increments by 5 every 5th second and retain the value for the whole of it

Ranch Hand
Posts: 33
• Number of slices to send:
Optional 'thank-you' note:
Hi.

I have made a swing application. It uses timer FOR performing certain tasks and it uses the following code get the current second:

Now, if the current second is completely divisible by 5, then a graph is updated.ie. graph gets updated every 5th second The graph should begin at time, t = 0; So, what i have done is initialised a variable 'time' to 0. When the second got from above code is divisible by 5, then graph is updated and time is incremented by 5.
Now, the graph is updated for the whole of the 5th second. Now, the problem i face is that the variable time is getting incemented by 5 twice in the 5th second...so, i am multiple values of x-axis (which corresponds to time) as the variable 'time' represents the x-axis, and hece, a wrong result.
I want the variable time to retain the same value for the whole of 5th second and get incremented by 5 in th enext 5th second.
Any idea?
Thanks!

Ranch Hand
Posts: 525
• Number of slices to send:
Optional 'thank-you' note:
How about setting the timer to a 5-second interval?
Then you can run your process every time it wakes up.
Am I missing something?

Jim ... ...

Rose Jac
Ranch Hand
Posts: 33
• Number of slices to send:
Optional 'thank-you' note:
well. A whole task is perofrmed, like repainting of panels, continuously for 100seconds and the graph is plotted evyr 5th second. So i cant do that.

Marshal
Posts: 74348
334
• Number of slices to send:
Optional 'thank-you' note:
What are you doing that runs continuously for 100 seconds?

Rose Jac
Ranch Hand
Posts: 33
• Number of slices to send:
Optional 'thank-you' note:
Repainting of panels...actually, several circles and few images that are redrawn using timer, so as to create "motion".

Campbell Ritchie
Marshal
Posts: 74348
334
• Number of slices to send:
Optional 'thank-you' note:
And you can't take the timings from that to increment your number? Not sure what else to suggest. Anybody else?

Saloon Keeper
Posts: 13369
295
• Number of slices to send:
Optional 'thank-you' note:
So why can't you use a separate timer to plot the graph?

Bartender
Posts: 4568
9
• Number of slices to send:
Optional 'thank-you' note:
If you can't do that, and your other Timer is on a rapid time interval, you could try this:

- keep track of the last time the graph was drawn (obtained from System.currentTimeMillis())

- every step, compare the current time to the last time

- if it's more than 5 seconds, redraw the graph and update the "last time" variable

 Don't get me started about those stupid light bulbs.