Jeevan Mane
Jeevan Mane

Reputation: 49

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()
     {
       ....
      . ....
     }
}

Upvotes: 1

Views: 2316

Answers (4)

Shai Almog
Shai Almog

Reputation: 52760

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.

Upvotes: 0

Daydah
Daydah

Reputation: 371

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);

Upvotes: 0

Nirmal- thInk beYond
Nirmal- thInk beYond

Reputation: 12054

simply use

new Login().show();

Upvotes: 1

Mr. Sajid Shaikh
Mr. Sajid Shaikh

Reputation: 7251

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

Upvotes: 2

Related Questions