• Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Swing Timer

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
j shap
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic