在J2ME中切换多个页面

时间:2013-08-02 14:21:38

标签: java java-me midlet

美好的一天。我是J2ME的新手,刚开始构建应用程序。我遇到的挑战是,我有一个MIDlet和多个页面(表单)在不同的类中,并回到以前的页面,特别是midlet是一个问题。从AirtimeTopUp页面,我正在尝试回到SignedIn。但是我一直在犯错,我对下一步该做什么感到有点困惑。

  public class AirtimeTopUp extends Form implements CommandListener {

  private Command mNextCommand;
  private Command mBackCommand;
  private SignedIn dis;
  private SignedIn startUp;
  private List list;
  private ChoiceGroup choiceGroup;
  private Display displayMngr = null;
  MyPiDONumber form3 = null;

  public AirtimeTopUp(SignedIn dis) {

      super("Top Up");
      this.dis = dis;
      choiceGroup = new ChoiceGroup(null, Choice.EXCLUSIVE);
      choiceGroup.append("My PiDO Number", null);
      choiceGroup.append("Other Number", null);
      mNextCommand = new Command("Continue", Command.SCREEN, 1);
      mBackCommand = new Command("Back", Command.BACK, 2);
      append(choiceGroup);
      this.setCommandListener(this);
      addCommand(mNextCommand);
      addCommand(mBackCommand);
      Display.getDisplay(dis).setCurrent(this);
  }

  public void commandAction(Command c, Displayable d) {
      if (c == mNextCommand) {
          int index = choiceGroup.getSelectedIndex();
          if (choiceGroup.getString(index).startsWith("My")) {
               Display.getDisplay(dis).setCurrent(new MyPiDONumber(dis));
          } else if (choiceGroup.getString(index).startsWith("Other Number")) {

            }
      } else {
          if (c == mBackCommand) {
              Display.getDisplay(dis).setCurrent(new SignedIn(dis));
          }
      }
  }

}

这是我的MIDlet类:

 public class SignedIn extends MIDlet implements CommandListener {
   private List mList;
   private Command mExitCommand, mNextCommand;
   private Display displayMngr = null;
   private AirtimeTopUp airtime = null;


public SignedIn(){
  String[] stringElements = { "Airtime TopUp", "Transfer", "Cashout", "Balance", "Pay Bills", "Mini Statement", "Account Settings", "PayCom Contacts", "cCare" };
  //Image[] imageElements = { loadImage("airplane.png"), loadImage("car.png"), loadImage("hotel.png") };
  mList = new List("Welcome!", List.IMPLICIT, stringElements, null);

  mNextCommand = new Command("Next", Command.SCREEN, 0);
  mExitCommand = new Command("Exit", Command.EXIT, 0);
  mList.addCommand(mNextCommand);
  mList.addCommand(mExitCommand);
  mList.setCommandListener(this);
}

public void startApp() {
    Display.getDisplay(this).setCurrent(mList);
}

public void commandAction(Command c, Displayable s) {
    if (c == mNextCommand || c == List.SELECT_COMMAND) {
        int index = mList.getSelectedIndex();
        if(mList.getString(index).startsWith("Airtime")){
            new AirtimeTopUp(this);
        }
        else if(mList.getString(index).startsWith("Transfer")){
            Alert alert = new Alert("Your selection", "You chose " + mList.getString(index) + ".", null, AlertType.INFO);
            alert.setTimeout(Alert.FOREVER);
            displayMngr.setCurrent(alert, mList);
        }
    }
    else if (c == mExitCommand)
        notifyDestroyed();
}

0 个答案:

没有答案