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

📄 list1.java

📁 这是我收集的别人写的关于基本控件的例子
💻 JAVA
字号:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class List1 extends MIDlet implements CommandListener,ItemStateListener {

	private final static Command exitCommand = new Command("Exit", Command.EXIT, 1);

	private Display display;

	private Form mainForm;
	private TextField textfield;
 
	private ChoiceGroup group ;
	public List1() {

	}

	protected void startApp() {

		display = Display.getDisplay(this);

		mainForm = new Form("Choice Group");
		mainForm.append("These are the available choice group");
		
		Image[] imageArray = null;

		try {

			// load the duke image to place in the image array
			Image duke = Image.createImage("/Icon.png");

			// these are the images and strings for the choices.
			imageArray = new Image[] { duke, duke, duke, duke };
		} catch (java.io.IOException err) {
			// ignore the image loading failure the application can recover.
		}

		String[] stringArray = { "选项 A", "选项 B", "选项 C", "选项 D" };

		
		//group =		new ChoiceGroup("Exclusive", ChoiceGroup.EXCLUSIVE,
		//				stringArray, imageArray);
		//group =		new ChoiceGroup("Multiple", ChoiceGroup.MULTIPLE, stringArray,
		//				imageArray);
		//创建 Pop-Up类型的ChoiceGroup,只能在MIDP2.0平台才有
		group =	new ChoiceGroup("Pop-Up", ChoiceGroup.POPUP, stringArray,
						imageArray);
		textfield = new TextField("当前选项为:","选项 A",20,TextField.ANY);
		
		
		mainForm.append(group);
		mainForm.append(textfield);
	
		mainForm.addCommand(exitCommand);
		mainForm.setCommandListener(this);
		mainForm.setItemStateListener(this);

		display.setCurrent(mainForm);
	}

	public void commandAction(Command c, Displayable d) {

		if (c == exitCommand) {
			destroyApp(false);
			notifyDestroyed();
		}
	}

	protected void destroyApp(boolean unconditional) {
	}

	protected void pauseApp() {
	}

	
	public void itemStateChanged(Item item) {
		if( item instanceof ChoiceGroup)
        {
			textfield.setString(group.getString(group.getSelectedIndex()));
        }
		
	}
}

⌨️ 快捷键说明

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