开发者

In J2ME Using LWUIT library. How to call another Form?

How to call another Form? When I used form.show() method, component of another form are not displayed.

Example...

FirstForm.java

public class FirstForm extends MIDlet implements ActionListener
{
    Form frm_first = new Form("First");
    public Command cmd_Login;
    public void startApp()
    {
        Display.init(this);
        cmd_Login = new Command("Login");
        frm_first.addComponent(cmd_login);
        ......
    }
    public void pauseApp() {}

    public void destroyApp(boolean unconditional) {}

    public void actionPerformed(ActionEvent ae)
    {
        Command cmd = ae.getCommand();
        String strcmdName = cmd.getCommandName();

        if (strcmdName.equals("Login"))
        {
             //how to call Login开发者_运维问答 Form
        }
    }
} 

Login.java

public class Login extends Form implements ActionListener
{
     Form frm_Login = new Form("Login");
     Button btn_Login = new Button("Login");
     public Login()
     {
       ....
      . ....
     }
}


First you have to create Form in your class FirstForm. Like Form frm=new Form("First Form"); then add command your cmd_Login in form like frm.addCommand(cmd_Login); then set command Listener to form frm.setCommandListener(this); & need to be implements CommandListener in FirstForm not ActionListener. then in public void commandAction(Command c, Displayable d) { now you have to write code to go second Form. & One thing i noticed in your Login class, you always extending class Form & also creating Form object in Login class... If you are using extend class Form then dont create Form Object. Thanks


simply use

new Login().show();


The best way I have found to call a form from within another, after implementing a listener is to use this: showForm("name of Form", null);

Another way to call another form, but from within a component action is this: showContainer("name of Form",c, null);


This line is invoked before Display.init(this); Hence you get an exception and nothing works.

Form frm_first = new Form("First");

Move the initialization code after the Display.init(this) code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜