Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Trusted Contributor
Posts: 167
Registered: ‎06-30-2011
My Device: n/a
My Carrier: Koodo

Creating and displaying timers

Hi there, I'm curious about learning more about timers. Could someone point me in the right direction please.

 

I'm making a program that will have a timer with a start and stop button.

 

I made a tester using the millitime thing and its working, but I'm wondering how I can use a loop to have the .setText update the labelfield every second.

 

I saw somebody mention TimerTask, would that be easier or harder to use?

 

Thanks everyone!

Super Contributor
Posts: 257
Registered: ‎05-05-2011
My Device: 9700
My Carrier: AT&T

Re: Creating and displaying timers

typical skeleton would be:

private class MyTimer extends TimerTask {
     public void run() {
      //your code here
     }
}

Timer timer = new Timer();
//let's run our TimerTask every 1 second
timer.scheduleAtFixedRate(new MyTimer(), 0, 1000);