package com.le.task;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.Ticker;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import com.sun.midp.lcdui.Text;
/**
*
* @Author *
* @Date 2021-3-21上午9:29:14
* @Version 1.0.0
*
*/
public class ChoiceGroup extends MIDlet implements CommandListener,ItemStateListener{
private Display display;
private Command exitCommand;
private Form form;
private ChoiceGroup group;
private ChoiceGroup group1;
private ChoiceGroup group2;
// private StringItem stringItem;
private Ticker ticker;
public XLLChoiceGroup() {
// TODO Auto-generated constructor stub
form = new Form(null);
// 单选
group = new ChoiceGroup("你的性别",ChoiceGroup.EXCLUSIVE);
group.append("male", null);
group.append("female", null);
// 多选
group1 = new ChoiceGroup("选择爱吃的水果",ChoiceGroup.MULTIPLE);
group1.append("西瓜", null);
group1.append("哈密瓜", null);
group1.append("傻瓜", null);
// 按钮列表
group2 = new ChoiceGroup("选择学习的课程",ChoiceGroup.POPUP);
group2.append("java", null);
group2.append("python", null);
group2.append("php", null);
exitCommand = new Command("Exit", Command.EXIT, 1);
// stringItem = new StringItem("", "male");
ticker = new Ticker("male");
//
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
// form.append(stringItem);
form.setTicker(ticker);
form.append(group);
form.append(group1);
form.append(group2);
form.addCommand(exitCommand);
form.setCommandListener(this);
form.setItemStateListener((ItemStateListener) this);
display = Display.getDisplay(this);
display.setCurrent(form);
}
public void commandAction(Command cmd, Item arg1) {
// TODO Auto-generated method stub
if (exitCommand == cmd) {
try {
destroyApp(true);
} catch (MIDletStateChangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
notifyDestroyed();
}
}
public void itemStateChanged(Item item) {
// TODO Auto-generated method stub
if (item instanceof ChoiceGroup) {
// stringItem.setText(group.getString(group.getSelectedIndex()));
StringBuffer stringBuffer = new StringBuffer();
// 单选结果
stringBuffer.append(group.getString(group.getSelectedIndex()) +" " +"爱吃");
boolean[] choices = new boolean[group1.size()];
group1.getSelectedFlags(choices);
for (int i = 0; i < choices.length; i++) {
if (choices[i]) {
// 获取每一个多选结果
stringBuffer.append(group1.getString(i) +" ");
}
}
int p = group.getSelectedIndex();
if (p > -1) {
stringBuffer.append("课程: "+group2.getString(p));
}
ticker.setString(stringBuffer.toString());
}
}
public void commandAction(Command arg0, Displayable arg1) {
// TODO Auto-generated method stub
}
}
12-20
938
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交