my commands using lwuit not working properly ..

112 views Asked by At

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

1

There are 1 answers

2
Kalai Selvan Ravi On

Add command listener to the form appForm.

appForm.addCommandListener(this);