本帖最后由 杨兴庭 于 2013-7-28 22:52 编辑
一道作业题!
这样获取TextField的值对吗?可是最后还是显示不出来~!List 的值不会
小朋友一枚,求各位帮忙!谢谢!- import javax.microedition.midlet.MIDlet;
- import javax.microedition.midlet.MIDletStateChangeException;
- import javax.microedition.lcdui.*;
- public class zouye extends MIDlet implements CommandListener{
- private TextField tf1,tf2;
- private Form mainForm1,mainForm2,mainForm;
- private Command cm1,cm2,cm3,cm4;
- private ChoiceGroup list;
- public zouye() {
- }
- protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
- }
- protected void pauseApp() {
- }
- protected void startApp() throws MIDletStateChangeException {
- Display display = Display.getDisplay(this);
- tf1 = new TextField ("班级","",15,1);
- tf2 = new TextField ("姓名","",15,1);
- mainForm1 = new Form("请输入");
- mainForm1.append(tf1);
- mainForm1.append(tf2);
- cm1 = new Command("下一页", Command.SCREEN, 1);
- mainForm1.addCommand(cm1);
- mainForm1.setCommandListener(this);
- mainForm2 = new Form("请选择");
- String [] stringArray = {"男","女"};
- list = new ChoiceGroup("单选",Choice.EXCLUSIVE,stringArray,null);
- cm2 = new Command("上一页", Command.SCREEN, 1);
- cm3= new Command ("完成",Command.SCREEN,1);
- mainForm2.append(list);
- mainForm2.addCommand(cm2);
- mainForm2.setCommandListener(this);
- mainForm2.addCommand(cm3);
- mainForm2.setCommandListener(this);
- mainForm = new Form("显示");
- cm4 = new Command ("退出",Command.EXIT ,1);
- String a = tf1.getString();
- String b = tf2.getString();
- mainForm.append(a );
- mainForm.append(b);
- mainForm.addCommand(cm4);
- mainForm.setCommandListener(this);
- display.setCurrent(mainForm1);
- }
- public void commandAction(Command c, Displayable d) {
- Display display = Display.getDisplay(this);
- if (c == cm1){
- display.setCurrent(mainForm2);
- }
- if (c == cm2){
- display.setCurrent(mainForm1);
- }
- if (c == cm3){
- display.setCurrent(mainForm);
- }
- if (c == cm4){
- try{
- destroyApp(false);
- }catch(MIDletStateChangeException exception){
- System.out.println("MIDletStateChangeException");
- }
- notifyDestroyed();
- }
- }
- }
复制代码 |