Search code examples
java-melwuitlcdui

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 ?


Solution

  • 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
    }