ChoiceGroup单选模式及事件处理


import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class ChoiceGroupMIDlet extends MIDlet implements ItemStateListener{
 private Display display;
 private Form form;
 //单选模式
 private ChoiceGroup cg=new ChoiceGroup("工资水平:",Choice.EXCLUSIVE);
 //零或多选模式
 //private ChoiceGroup cg=new ChoiceGroup("工资水平:",Choice.MULTIPLE);
 //弹出模式
 //private ChoiceGroup cg=new ChoiceGroup("工资水平:",Choice.POPUP);
 public ChoiceGroupMIDlet() {
  display=Display.getDisplay(this);
  form =new Form("");
  cg.append("600以下", null);
  cg.append("600~1000", null);
  cg.append("3000~5000", null);
  cg.insert(2, "1000~3000", null);
  //cg.delete(1);
  //cg.deleteAll();
  form.append(cg);
  form.setItemStateListener(this);
 }

 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 {
  display.setCurrent(form);

 }

 

 public void itemStateChanged(Item item) {
  
  int num=cg.getSelectedIndex();
  System.out.println("你选择的是第"+num+"个:");
  String str=cg.getString(num);
  System.out.println(str);
 }

}

你可能感兴趣的:(String,null,Class,import)