在lWUIT中,如何通过单击后退命令来调用主MIDlet类?

发布于 2024-11-18 21:16:14 字数 323 浏览 3 评论 0原文

我的问题是如何通过单击返回命令来调用主MIDlet类?
假设 MainMIDlet.java 这个类扩展了 Form 并实现了 ActionListenerAboutus.java 这个类扩展还包括 Form 并实现 ActionListener。在这堂课中我没有创建形式对象。那么在这个类中,当点击Command后退按钮时如何调用MainMIDlet类呢?

My question is how to call main MIDlet class by clicking on back command?
Suppose MainMIDlet.java this class extends Form and implements ActionListener and Aboutus.java this class extends also include Form with implements ActionListener. In this class I had not created object of form. So in this class how to call MainMIDlet class when click on Commmand back button?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

£冰雨忧蓝° 2024-11-25 21:16:15

调用 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();
            }
        }
}

Aboutus.java

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
            }
        }
}

Pass the MainMIDlet form instance when you call the Aboutus.java.
For example,

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

Aboutus.java

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
            }
        }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文