Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Programmer > Easily implemen...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 52661 of 53789
Post > Topic >>

Easily implementing a Timer

by "DaveN" <DaveN@[EMAIL PROTECTED] > May 12, 2008 at 12:29 PM

Hi All,

I've just started with Java in the last couple of days and am now having 
some trouble finding a clear description of implementing a timer, this 
however may be down to my lack of experience with OOP, so I apologise if 
that's the case! :-)

I understand the need for the java.util.timer/Task cl***** to get the 
correct things available to me.

I need to have a timer running in a background thread that calls a
function 
every say 1s.  That function will do some things like updating a screen 
message and some other application calculations.  It also needs to stop
the 
timer when the necessary conditions are met.  The timer will have been 
started when the user requests.

My pseudo java code for this is something like:


void MainFunction()
{
    if(UserMakesStartSelection == 1)
    {
        Timer timer = new CreateNewTimer( TimerFunctionToCall, StartNow, 
Every1000ms)
    }
}


void TimerFunctionToCall()
{
    /* Gets called every 1000ms */
    /* Do some things */
    GetTimeElapsed();
    UpdateScreen();
    .
    .
    .
    etc

    /* Check conditions */
    if(TimeToStop == 1)
    {
        StopTimer(timer);
    }
}

All the examples I've seen seem to have these functions all wrapped
together 
in a class which makes it difficult to understand and follow.  Like I say 
it's probably my lack of OOP but if anyone can help to clear the muddy 
waters I would appreciate it.


-- 
DaveN
 




 5 Posts in Topic:
Easily implementing a Timer
"DaveN" <Dav  2008-05-12 12:29:09 
Re: Easily implementing a Timer
ram@[EMAIL PROTECTED] (S  2008-05-12 11:57:57 
Re: Easily implementing a Timer
Roedy Green <see_websi  2008-05-12 12:50:49 
Re: Easily implementing a Timer
"DaveN" <Dav  2008-05-12 23:33:23 
Re: Easily implementing a Timer
"DaveN" <Dav  2008-05-13 00:09:18 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 23:29:17 CDT 2008.