1

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()
     {
       ....
      . ....
     }
}
gnat
  • 6,213
  • 108
  • 53
  • 73

4 Answers4

2

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

Mr. Sajid Shaikh
  • 7,051
  • 4
  • 21
  • 35
1

simply use

new Login().show();
Nirmal- thInk beYond
  • 11,847
  • 8
  • 35
  • 46
  • In login form its necessary to define all defination of component in login constructor. If not what is solution.plz give some example. thank u very much – Jeevan Mane Jul 04 '11 at 10:57
0

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

Daydah
  • 372
  • 7
  • 20
0

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.

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