A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

本帖最后由 杨兴庭 于 2013-7-28 22:52 编辑

一道作业题!
这样获取TextField的值对吗?可是最后还是显示不出来~!List 的值不会
小朋友一枚,求各位帮忙!谢谢!
  1. import javax.microedition.midlet.MIDlet;
  2. import javax.microedition.midlet.MIDletStateChangeException;
  3. import javax.microedition.lcdui.*;


  4. public class zouye extends MIDlet implements CommandListener{
  5. private TextField tf1,tf2;
  6. private Form mainForm1,mainForm2,mainForm;
  7. private Command cm1,cm2,cm3,cm4;
  8. private ChoiceGroup list;

  9. public zouye() {

  10. }

  11. protected void destroyApp(boolean arg0) throws MIDletStateChangeException {


  12. }

  13. protected void pauseApp() {


  14. }

  15. protected void startApp() throws MIDletStateChangeException {
  16. Display display = Display.getDisplay(this);

  17. tf1 = new TextField ("班级","",15,1);
  18. tf2 = new TextField ("姓名","",15,1);
  19. mainForm1 = new Form("请输入");
  20. mainForm1.append(tf1);
  21. mainForm1.append(tf2);
  22. cm1 = new Command("下一页", Command.SCREEN, 1);
  23. mainForm1.addCommand(cm1);
  24. mainForm1.setCommandListener(this);

  25. mainForm2 = new Form("请选择");
  26. String [] stringArray = {"男","女"};
  27. list = new ChoiceGroup("单选",Choice.EXCLUSIVE,stringArray,null);
  28. cm2 = new Command("上一页", Command.SCREEN, 1);
  29. cm3= new Command ("完成",Command.SCREEN,1);
  30. mainForm2.append(list);
  31. mainForm2.addCommand(cm2);
  32. mainForm2.setCommandListener(this);
  33. mainForm2.addCommand(cm3);
  34. mainForm2.setCommandListener(this);

  35. mainForm = new Form("显示");
  36. cm4 = new Command ("退出",Command.EXIT ,1);
  37. String a = tf1.getString();
  38. String b = tf2.getString();
  39. mainForm.append(a );
  40. mainForm.append(b);
  41. mainForm.addCommand(cm4);
  42. mainForm.setCommandListener(this);

  43. display.setCurrent(mainForm1);


  44. }

  45. public void commandAction(Command c, Displayable d) {
  46. Display display = Display.getDisplay(this);
  47. if (c == cm1){
  48. display.setCurrent(mainForm2);
  49. }        
  50. if (c == cm2){
  51. display.setCurrent(mainForm1);
  52. }
  53. if (c == cm3){
  54. display.setCurrent(mainForm);


  55. }
  56. if (c == cm4){
  57. try{
  58. destroyApp(false);
  59. }catch(MIDletStateChangeException exception){
  60. System.out.println("MIDletStateChangeException");
  61. }
  62. notifyDestroyed();
  63. }

  64. }

  65. }
复制代码

评分

参与人数 1技术分 +1 收起 理由
杜光 + 1 每天提问并回答问题,是对知识的复习和积累.

查看全部评分

1 个回复

倒序浏览
  1. public void itemStateChanged(Item i) {
  2. if (i ==tf1) {
  3. String a = tf1.getString();
  4. }
  5. if (i == this.tf2) {
  6. String  b = tf2.getString();
  7. }
  8. }
复制代码
第一先就着你的代码说吧~~你没有写Item组件变化监听方法,我上面给你写了~~~~
第二 最好把 字符串 a和b弄成全局变量
第三 你的代码结构很混乱 估计你是刚起步吧~~~多看看别人代码的格式~~培养一下你的编程思想

评分

参与人数 1技术分 +1 收起 理由
杨兴庭 + 1

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马