⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 choicegrouptest.java

📁 java手机程序开发光盘源码(第六章)
💻 JAVA
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class ChoiceGroupTest extends MIDlet implements CommandListener, ItemStateListener{

	Display display;
	Form form;
	ChoiceGroup exclusive, multiple;
	Command exitCmd;
	String sex = "男性";
	String fruit = "";
	Ticker ticker;

	public ChoiceGroupTest(){
		display = Display.getDisplay(this);
		form = new Form("ChoiceGroup练习");
		exclusive = new ChoiceGroup("你的性别", Choice.EXCLUSIVE);
		multiple = new ChoiceGroup("爱吃的水果", Choice.MULTIPLE);
		exitCmd = new Command("退出", Command.EXIT, 1);
		ticker = new Ticker(sex+",爱吃"+fruit);
		exclusive.append("男性", null);
		exclusive.append("女性", null);
		multiple.append("西瓜", null);
		multiple.append("苹果", null);
		form.setTicker(ticker);
		form.append(exclusive);
		form.append(multiple);
		form.addCommand(exitCmd);
		form.setCommandListener(this);
		form.setItemStateListener(this);
	}


	public void startApp(){
		display.setCurrent(form);

	}

	public void pauseApp(){


	}

	public void destroyApp(boolean unconditional){

	}

	public void commandAction(Command c, Displayable d){
		if(c == exitCmd){
			destroyApp(true);
			notifyDestroyed();
		}
	}

	public void itemStateChanged(Item item){
		if(item == exclusive){
			int index = exclusive.getSelectedIndex();
			sex = exclusive.getString(index);

		}
		else if(item == multiple){
			boolean[] selectedIndex = new boolean[multiple.size()];
			multiple.getSelectedFlags(selectedIndex);
			for(int i=0;i<selectedIndex.length;i++){
				if(selectedIndex[i])
					fruit += multiple.getString(i)+" ";

			}
		}
		ticker.setString(sex+",爱吃"+fruit);
		fruit = "";
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -