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
Contributor
Posts: 17
Registered: ‎03-04-2010
My Device: 9530
My Carrier: AT&T

Real-Time Clock, Could use some help

Hello everyone, seems like a great community Smiley Tongue

 

I am working on something that i thought of, but im kinda stuck on the first step, getting real time clock to work.  I cant seem to get it update, so could someone recommend on how to go about it?

What i am trying to do in my code is rewrite the same label every second or so with a timer, and i have been failing so far, I dont know any other way of doing this?

Could some one help me with some tips, and code would be useful to see.

Here is my clock code that i wrote:

 

        Calendar time = Calendar.getInstance();
        
       int Hour = time.get(Calendar.HOUR_OF_DAY);
       String hour = Integer.toString(Hour);
       if (Hour <= 9)
        {
         hour = hour.trim();
         hour = "0" + hour;
        }

        int Min = time.get(Calendar.MINUTE);
        String min = Integer.toString(Min);
        if (Min <= 9)
        {
          min = min.trim();
          min = "0" + min;
        }

        int Sec = time.get(Calendar.SECOND);
        String sec = Integer.toString(Sec);
        if (Sec <= 9)
        {
          sec = sec.trim();
          sec = "0" + sec;
        }
        
        add(new LabelField("The current time is: ",LabelField.FIELD_HCENTER));
        LabelField q = new LabelField(hour + ":" + min + ":" + sec,LabelField.FIELD_HCENTER);
        add(q);
        
        Timer l = new Timer();
 //       l.schedule(update, 1);
  }
    {
        Calendar time = Calendar.getInstance();
      
        int Hour = time.get(Calendar.HOUR_OF_DAY);
        String hour = Integer.toString(Hour);
        if (Hour <= 9)
        {
              hour = hour.trim();
              hour = "0" + hour;
        }

        int Min = time.get(Calendar.MINUTE);
        String min = Integer.toString(Min);
        if (Min <= 9)
        {
              min = min.trim();
              min = "0" + min;
        }

        int Sec = time.get(Calendar.SECOND);
        String sec = Integer.toString(Sec);
        if (Sec <= 9)
        {
              sec = sec.trim();
              sec = "0" + sec;
        }

Thanx for your time

Hope i can get this working Smiley Tongue

 

Developer
Posts: 133
Registered: ‎07-20-2009
My Device: Not Specified

Re: Real-Time Clock, Could use some help

I think it can be use System.currentTimeMillis(),

and then use DateFormat 's formatLocal which can get the current time very easily

Contributor
Posts: 17
Registered: ‎03-04-2010
My Device: 9530
My Carrier: AT&T

Re: Real-Time Clock, Could use some help

ok,

right now i have a LabelField which displays my hour mins secs.

for some reason i cant seem to change its contents once they are written into it.

 

should i try using something else rather than a LabelField?

any ideas?

Developer
Posts: 133
Registered: ‎07-20-2009
My Device: Not Specified

Re: Real-Time Clock, Could use some help

did you update the screen after change value of the label

invalidate it.

Contributor
Posts: 17
Registered: ‎03-04-2010
My Device: 9530
My Carrier: AT&T

Re: Real-Time Clock, Could use some help

[ Edited ]

are you talking about this?

ill try it in a bit

 

public void invalidateLayout()

Invalidates this screen's layout (including all controlled fields).

 

also there is this one

invalidate

public void invalidate(int x,
int y,
int width,
int height)