Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switching between LWUIT Form and LCDUI Form

I have built a LWUIT UI class which contains the Midlet. I am basically using a theme from this midlet. But I need to jump to another LCDUI form which contains some LCDUI controls and I need to set display that LCDUI form. So is it possible to jump from LWUIT form to LCDUI form and set display the LCDUI form ? If possible how ?

like image 356
Abdullah Md. Zubair Avatar asked Jul 10 '11 06:07

Abdullah Md. Zubair


2 Answers

I used following code to show the both LWUIT Form and LCDUI Form. See the sample code.

com.sun.lwuit.Form lwuitForm;
protected void startApp() throws MIDletStateChangeException {
    Display.init(this);
    lwuitForm = new com.sun.lwuit.Form("LWUIT Form");
    lwuitForm.addComponent(new TextField(""));

    final MIDlet midlet = this;
    final Command abtUsCmd = new Command("Next") {
        public void actionPerformed(ActionEvent evt) {
            javax.microedition.lcdui.Form  frm = new javax.microedition.lcdui.Form("LCDUI Form");
            StringItem item = new StringItem("Text", "Sample text");
            frm.append(item);

            final javax.microedition.lcdui.Command cmd = new javax.microedition.lcdui.Command("Back", javax.microedition.lcdui.Command.BACK, 0);
            CommandListener cmdLis = new CommandListener() {

                public void commandAction(javax.microedition.lcdui.Command c, Displayable d) {
                    if(c == cmd) {
                        Display.init(midlet);
                        lwuitForm.show(); // Show the LWUIT form again
                    }
                }
            };

            frm.setCommandListener(cmdLis);
            frm.addCommand(cmd);

            javax.microedition.lcdui.Display.getDisplay(midlet).setCurrent(frm); // show the LCDUI Form
        }
    };
    lwuitForm.addCommand(abtUsCmd);
    lwuitForm.show(); // Show the LWUIT Form
}
like image 147
bharath Avatar answered Nov 20 '22 11:11

bharath


This looks tricky, but yeah, we can switch between both. The trick is when u show the LWUIT form, after it has been successfully painted on the screen, make a call to

javax.microedition.lcdui.Display.getDisplay(midlet).getCurrent();

this gives you the Displayable holding all the LWUIT views, so with this, you can always switch to LCDUI, and back to LWUIT with the LCDUI's

display.setCurrent

Let me know if this works for you. Thanks

like image 21
Kingsley Adio Avatar answered Nov 20 '22 13:11

Kingsley Adio