Search code examples
java-melwuit

Showing Time on LWUIT Soft Button bar


I'd like to show the time (HH:MM) in the middle of the soft button bar (eg like in Opera Mini or UC Browser 8.6) in LWUIT. I have used this code to get device time.

String  getDateString ( Date  date ) {
Calendar  calendar  = Calendar . getInstance ();
calendar . setTime ( date );
 int  hour  =  calendar . get ( Calendar . HOUR_OF_DAY );
 int  minute  =  calendar . get ( Calendar . MINUTE );

That is as far as I could go since I've never used time in J2ME. The time also needs to be updated like a normal clock, most likely through a thread. How do I go about this?


Solution

  • 1) Took the time in the format of HH:MM

    String time = String.valueOf(hour).concat(":").concat(String.valueOf(minute));
    

    2) Set the thirdsoftbutton to true for adding center soft button

    Display.getInstance().setThirdSoftButton(true);
    

    3) Create a command with the value of time and add it to the form

    frmObj.addCommand(new Command(time));
    

    Now, you will have the time at the middle of the soft button bar.