Forums Register Login

Swing Timer

+Pie Number of slices to send: Send
Hi-

I'm using a Swing Timer to run an animation in an applet. In every cycle a calculation is done and a figure drawn on a BufferedImage, and that image is drawn to my JPanel subclass via PaintComponent, via repaint(). The timing is sometimes extremeley ragged. I've measured elapsed time at various points in the cycle by printing out Date.getTime(), and my code takes 10 or 20 or 30 ms to run at each cycle (I don't know why such round numbers!). But when I have the timer set to 50 ms or less, the timer seems to often delay firing so that cycles will take 50-100 ms. The timer works perfectly when the delay is 100ms, but not dependably for delay <= 50ms, which I need. (I'm running AppletViewer under WinXP, 1.6GHz PentiumIV)



startRot() is called in response to a button push. As I said, updateimage() and paintComponent() usually finish withing 30ms of the timer firing. Any clues as to why the timer won't just fire every 50ms? Thanks.

JS
+Pie Number of slices to send: Send
JS,
I'm not sure, but it may be due to the Windows clock granularity.
Here are the results of a search I did of the "comp.lang.java*" newsgroups. It may be helpful.

Good Luck,
Avi.
+Pie Number of slices to send: Send
Avi,

Thanks for the search. The consensus seems to be that clock granularity on WinXP is 10ms. I don't see how this quite explains the timer sometimes firing 30-50ms late. And then there are stretches where it performs fine. No doubt this has to do with my OS sometimes eating up a lot of time elsewhere, but shouldn't the timer still fire within 10ms of the specified 50ms delay? Anyway, thanks for your efforts.

Jon
Straws are for suckers. Now suck on this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 884 times.
Similar Threads
NPE when trying to get size() in ArrayList
To make moving ball
JSpinner sending multiple events
Updation of ProgressBar??
i got into a unexplainable situtation pleas help
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:36:41.