Java me 在lWUIT中,如何通过单击back命令调用主MIDlet类?

Java me 在lWUIT中,如何通过单击back命令调用主MIDlet类?,java-me,lwuit,Java Me,Lwuit,我的问题是如何通过单击backcommand? 假设MainMIDlet.java这个类扩展Form并实现ActionListener和Aboutus.java这个类扩展还包括Form和implementsActionListener。在这个类中,我没有创建表单对象。因此,在这个类中,当单击Commmandback按钮时如何调用MainMIDlet类?在调用Aboutus.java时传递MainMIDlet表单实例。 比如说, MainMIDlet.java public class Main

我的问题是如何通过单击back
command


假设
MainMIDlet.java
这个类扩展
Form
并实现
ActionListener
Aboutus.java
这个类扩展还包括
Form
和implements
ActionListener
。在这个类中,我没有创建表单对象。因此,在这个类中,当单击
Commmand
back按钮时如何调用
MainMIDlet
类?

在调用Aboutus.java时传递MainMIDlet表单实例。 比如说,

MainMIDlet.java

 public class MainMIDlet extends MIDlet implements ActionListener {
    Form form = new form();
    ...
    ...

    public void actionPerformed(ActionEvent ae)
        {
            Command cmd = ae.getCommand();
            String cmdname= cmd.getCommandName();

            if (cmdname.equals("Aboutus"))
            {
                 Aboutus aboutus = new Aboutus(form); // pass the current form
                 aboutus.show();
            }
        }
}
public class Aboutus extends Form implements ActionListener {

Form mainform;

 public Aboutus(Form form) {
   this.mainform = form;
   ...
   ...
   Command backCommand = new Command("Back",null,1);
   this.setBackCommand(backCommand);
 }
    ...
    ...

    public void actionPerformed(ActionEvent ae)
        {
            Command cmd = ae.getCommand();
            String cmdname= cmd.getCommandName();

            if (cmdname.equals("Back"))
            {
                 mainform.showBack(); // show the Main Midlet form here
            }
        }
}
Aboutus.java

 public class MainMIDlet extends MIDlet implements ActionListener {
    Form form = new form();
    ...
    ...

    public void actionPerformed(ActionEvent ae)
        {
            Command cmd = ae.getCommand();
            String cmdname= cmd.getCommandName();

            if (cmdname.equals("Aboutus"))
            {
                 Aboutus aboutus = new Aboutus(form); // pass the current form
                 aboutus.show();
            }
        }
}
public class Aboutus extends Form implements ActionListener {

Form mainform;

 public Aboutus(Form form) {
   this.mainform = form;
   ...
   ...
   Command backCommand = new Command("Back",null,1);
   this.setBackCommand(backCommand);
 }
    ...
    ...

    public void actionPerformed(ActionEvent ae)
        {
            Command cmd = ae.getCommand();
            String cmdname= cmd.getCommandName();

            if (cmdname.equals("Back"))
            {
                 mainform.showBack(); // show the Main Midlet form here
            }
        }
}

谢谢bhakki yaar。您提供了最佳解决方案,但问题是当单击“上一步”命令时,没有执行任何操作,即无法显示MainMIDlet表单。在我的MainMIDlet类中,所有组件都是在MainMIDlet的form对象[form form=new form()]的帮助下添加的。问题是什么?请给我溶液。谢谢U@Jeevan:您是否将
addCommandListener
添加到第二个表单中?非常感谢bhakki。我忘记了这个方法。再次感谢你,伙计。保重。@Jeevan:开始接受答案吧。提高你的声誉。@Jeevan:请看并阅读。