开发者

In lWUIT, How to call main MIDlet class by click on back command?

开发者 https://www.devze.com 2023-03-17 07:47 出处:网络
My question is how to call main MIDlet class by clicking on back command? Suppose MainMIDlet.java this class extends Form and implements ActionListener andAboutus.java this class extends also include

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?


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

精彩评论

暂无评论...
验证码 换一张
取 消