wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Creating Timer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Creating Timer" Watch "Creating Timer" New topic
Author

Creating Timer

TesL lian
Greenhorn

Joined: Feb 27, 2009
Posts: 4
How am i suppose to create a timer? i am looking for something to replace my Thread.sleep which seems to be slowing down my program.


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42641
    
  65
If Thread.sleep slows down the code, why do you have it in there?


Ping & DNS - my free Android networking tools app
TesL lian
Greenhorn

Joined: Feb 27, 2009
Posts: 4
i am looking for some sort of delays which does not affect my rendering loop. is there other recommendation? actually what i need is something more real-time then i can keep track of the different time for the different location.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

In what thread do you do the rendering? Is this is Swing application, or something else?

In Swing, you can use javax.swing.Timer combined with an ActionListener.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Daesung Park
Ranch Hand

Joined: Mar 22, 2007
Posts: 68
Take a look at http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html#scheduleAtFixedRate(java.lang.Runnable,%20long,%20long,%20java.util.concurrent.TimeUnit) and its implementing classes.

Daesung Park

BLOG
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39880
    
  28
Sounds like a Swing-related question which I ought to move.
TesL lian
Greenhorn

Joined: Feb 27, 2009
Posts: 4
Solved. Thanks all for your help.
 
 
subject: Creating Timer