当前位置: 代码迷 >> J2ME >> 一个代码上的小有关问题,请教下
  详细解决方案

一个代码上的小有关问题,请教下

热度:1187   发布时间:2016-04-17 22:22:06
一个代码上的小问题,请教下
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * @author Administrator
 */
public class Tex extends MIDlet implements CommandListener{
  A a;
  private Display dis;
  private TextBox tb;
  private Command exit,input;
  private List conL;
  static final String[] conN = {
  "any",
  "Num",
  "Email",
  "shi zhi",
  "phone",
  "URL",
  };
  static final int[] conT = {
  TextField.ANY,
  TextField.NUMERIC,
  TextField.EMAILADDR,
  TextField.DECIMAL,
  TextField.PHONENUMBER,
  TextField.URL,
  };

  class A implements CommandListener{
public void commandAction(Command c, Displayable d) {
if(c == exit){
dis.setCurrent(conL);
}

throw new UnsupportedOperationException("Not supported yet.");
}
}
  public Tex(){
  dis = Display.getDisplay(this);
  exit = new Command("退出",Command.SCREEN,1);

  tb = new TextBox("","",200,0);
  conL = new List("选择类型",Choice.IMPLICIT,conN,null);
  tb.addCommand(exit);
  tb.setCommandListener(a);
  conL.addCommand(exit);
  conL.setCommandListener(this);


  }

  public void startApp() {
  dis.setCurrent(conL);
  }

  public void pauseApp() {
  }

  public void destroyApp(boolean unconditional) {
  }


  public void commandAction(Command c, Displayable d) {
  if(d.equals(conL)){

  if(c == exit){
  destroyApp(false);
  notifyDestroyed();
  }
   
  int t = ((List)d).getSelectedIndex();
  tb.setTitle(conN[t]);
  tb.setConstraints(conT[t]);
  dis.setCurrent(tb);
   
  }
  throw new UnsupportedOperationException("Not supported yet.");
  }
}



以上程序运行后会出现一个List,选择后出现一个TexBox,可以根据选择的不同而使输入类型不同。
我在List界面上选择退出时会结束程序(这个倒是行的)
我想在TextBox界面上选择退出时,返回到List那个界面。
所以我尝试着定义了一个类A 
用了上述的代码希望实现这个功能,但是没用啊
所以想要请教下应该怎么写才能实现我说的功能呢?

------解决方案--------------------
Java code
/*  * To change this template, choose Tools | Templates  * and open the template in the editor.  */import javax.microedition.lcdui.Choice;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.CommandListener;import javax.microedition.lcdui.Display;import javax.microedition.lcdui.Displayable;import javax.microedition.lcdui.List;import javax.microedition.lcdui.TextBox;import javax.microedition.lcdui.TextField;import javax.microedition.midlet.MIDlet;/** * @author Administrator */public class Tex extends MIDlet implements CommandListener {    private Display dis;    private TextBox tb;    private Command exit, input;    private List conL;    static final String[] conN = { "any", "Num", "Email", "shi zhi", "phone",            "URL", };    static final int[] conT = { TextField.ANY, TextField.NUMERIC,            TextField.EMAILADDR, TextField.DECIMAL, TextField.PHONENUMBER,            TextField.URL, };    public Tex() {        dis = Display.getDisplay(this);        exit = new Command("退出", Command.SCREEN, 1);        tb = new TextBox("", "", 200, 0);        conL = new List("选择类型", Choice.IMPLICIT, conN, null);        tb.addCommand(exit);        tb.setCommandListener(this);// 注册监听器        conL.addCommand(exit);        conL.setCommandListener(this);    }    public void startApp() {        dis.setCurrent(conL);    }    public void pauseApp() {    }    public void destroyApp(boolean unconditional) {    }    public void commandAction(Command c, Displayable d) {        if (d.equals(conL)) {            if (c == exit) {                destroyApp(false);                notifyDestroyed();            }            int t = ((List) d).getSelectedIndex();            tb.setTitle(conN[t]);            tb.setConstraints(conT[t]);            dis.setCurrent(tb);        } else if (d == tb) {// 当前是TextBox            if (c == exit) {// 按退出,返回到List                dis.setCurrent(conL);            }        }    }}
  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!