黑马程序员技术交流社区
标题:
一道作业题!求助!怎样获取TextField输入的内容和ChoiceGroup...
[打印本页]
作者:
nuoxi0318
时间:
2013-7-25 18:28
标题:
一道作业题!求助!怎样获取TextField输入的内容和ChoiceGroup...
本帖最后由 杨兴庭 于 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();
}
}
}
复制代码
作者:
黑马陈凯
时间:
2013-7-28 15:24
public void itemStateChanged(Item i) {
if (i ==tf1) {
String a = tf1.getString();
}
if (i == this.tf2) {
String b = tf2.getString();
}
}
复制代码
第一先就着你的代码说吧~~你没有写Item组件变化监听方法,我上面给你写了~~~~
第二 最好把 字符串 a和b弄成全局变量
第三 你的代码结构很混乱 估计你是刚起步吧~~~多看看别人代码的格式~~培养一下你的编程思想
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2