1

I am trying to move between 3 forms. 1 is main form and 2 other simple forms. I have commands in the soft keys but they are not working...

below is my code...

public class checkOutComponents extends MIDlet implements ActionListener 
{

    private Form appForm;
    private Form f1;
    private Form f2;
    Command GoTof1 = new Command("GoTof1");
    Command GoTof2 = new Command("GoTof2");
    Command GoToMainForm = new Command("GoToMainForm");
    public void startApp() 
    {
        Display.init(this);

        appForm = new Form("Check These Components!! ");
        appForm.setLayout(new BorderLayout());

        appForm.addCommand(GoTof1);
        appForm.addCommand(GoTof2);

        appForm.addComponent(BorderLayout.CENTER, formContainer);
        appForm.show();
    }

    public void pauseApp() 
    {

    }

    public void destroyApp(boolean unconditional) 
    {

    }

    public void actionPerformed(ActionEvent event)
    {
        Command eventCmd = event.getCommand();
        Form f = Display.getInstance().getCurrent();

        boolean sentido = false;
        if (eventCmd == GoTof1) 
        {
            sentido = true;
            Image i1 = null;
            try 
            {
                i1 = Image.createImage("/hello/1.jpeg");
            } 
            catch (IOException ex) 
            {
                ex.printStackTrace();
            }
            Label lab1 = new Label(i1);
            f1.addComponent(lab1);
            f1.addCommand(GoTof2);
            f1.addCommand(GoToMainForm);
            f.setTransitionOutAnimator(Transition3D.createCube(300, sentido));
            f1.show();

        } 
        else if (eventCmd == GoTof2) 
        {
            sentido = false;
            Image i2 = null;
            try 
            {
                i2 = Image.createImage("/hello/2.jpeg");
            } 
            catch (IOException ex) 
            {
                ex.printStackTrace();
            }
            Label lab2 = new Label(i2);
            f1.addComponent(lab2);
            f1.addCommand(GoTof1);
            f1.addCommand(GoToMainForm);
            f.setTransitionOutAnimator(Transition3D.createCube(300, sentido));
            f2.show();
        }
        else if(eventCmd == GoToMainForm)
        {
            appForm.showBack();

        }

    }

}

Kindly help regarding this. Thanks in advance and regards, Swati

Kalai Selvan Ravi
  • 2,846
  • 2
  • 16
  • 28
swatijoshi
  • 51
  • 2

1 Answers1

1

Add command listener to the form appForm.

appForm.addCommandListener(this);
Kalai Selvan Ravi
  • 2,846
  • 2
  • 16
  • 28
  • Thanks a lot Kalai this worked perfectly fine :) But i have another requirement where i want to go to the MidletSuite (Main Screen from where we launch the Midlet) with Exit command from any one of the form. How can i achieve it? – swatijoshi Sep 06 '12 at 11:23
  • For the HomeScreen, add Exit command. If you are showing another screen after HomeScreen, pass home screen form obj to that screen and add back command to it. In back command event, just show that received obj. Just follow this hierarchy, when displaying more than one screens. – Kalai Selvan Ravi Sep 06 '12 at 11:46