我的命令使用lwuit无法正常工作..

时间:2012-09-05 09:46:36

标签: lwuit lwuit-form lwuit-resource-editor lwuit-layouts lwuit-command

我想在三种形式之间移动。 1是主要形式和2个其他简单形式。 我在软键中有命令,但它们不起作用......

下面是我的代码......

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

        }

    }

}

请帮忙解决这个问题。 在此先感谢和问候, 斯瓦特

1 个答案:

答案 0 :(得分:1)

将命令侦听器添加到表单appForm。

appForm.addCommandListener(this);