日期:2014-05-20 浏览次数:20709 次
package gesanri; 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; public class City implements CommandListener{ private Displayable displayable; private Display display; private Form form; private Command back; private ChoiceGroup province; private ChoiceGroup city; private String[][] provinceAndCity; public City(Display display,Displayable displayable) { this.display = display; this.displayable = displayable; display = Display.getDisplay(MainMidlet.instance); provinceAndCity = new String[][]{{"直辖市","北京","上海","天津","重庆"},{"特别行政区","香港","澳门"},{"黑龙江","哈尔滨","齐齐哈尔","牡丹江","大庆","伊春","双鸭山","鹤岗","鸡西","佳木斯","七台河","黑河","绥化","大兴安岭"}}; form = new Form("新增城市"); back = new Command("返回",Command.BACK,1); province = new ChoiceGroup("省份:",ChoiceGroup.POPUP); city = new ChoiceGroup("城市:",ChoiceGroup.POPUP); province.append("请选择", null); for(int i = 0; i < provinceAndCity.length; i++) province.append(provinceAndCity[i][0], null); city.append("请选择", null); form.append(province); form.append(city); form.addCommand(back); form.setCommandListener(this); } public void show(){ display.setCurrent(form); } public void commandAction(Command c, Displayable dpa) { if(c == back){ display.setCurrent(displayable); } } }