专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > J2ME

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

发布时间:2010-06-05 12:43:21 文章来源:www.iduyao.cn 采编人员:星星草
一个代码上的小问题,请教下
/*
 * 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);
            }
        }
    }
}
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: