1

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?

Chris Mwai
  • 91
  • 1
  • 14

2 Answers2

1

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.

Kalai Selvan Ravi
  • 2,846
  • 2
  • 16
  • 28
  • 1
    Thanks for your help. However, your method adds two commands to my Form. When you add Display.getInstance().setThirdSoftButton(true); LWUIT adds a button that changes its string name value depending on the component on focus ie. if you focus on a text area, it changes to "Edit" and changes to "Select" when you focus on any selectable component. The other command that with the "time" value is added to the menu dialog. The time, as I suspected, is always constant so it seems there should be a thread implemented to update time string. How can I control the behavior of the third soft button? – Chris Mwai Sep 26 '12 at 09:15
1

Set a glass pane that draws the time at that specific location.

And on LWUIT 1.5/Codename One you can derive the MenuBar and add your component into it.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65