imageitemdemo.java

来自「《精通JAVA手机游戏与应用程序设计》随书光盘」· Java 代码 · 共 52 行

JAVA
52
字号

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;

public class ImageItemDemo extends MIDlet implements CommandListener {

	private Command exitCommand = new Command("退出", Command.EXIT, 1);

	private Form mainForm;

	private ImageItem pngItem_1,pngItem_2;

	public ImageItemDemo() {
		mainForm = new Form("ImageItem");
	}

	protected void startApp() {

		mainForm.append("显示各种类型的ImageItem");

		try {
			//程序创建时添加默认布局的图像
			pngItem_1 = new ImageItem("默认图像控件", Image.createImage("/Image.png"),
					Item.LAYOUT_DEFAULT, "小猪图片");
			pngItem_2 = new ImageItem("默认图像控件", Image.createImage("/Image.png"),
					Item.LAYOUT_2|Item.LAYOUT_EXPAND|Item.LAYOUT_NEWLINE_BEFORE, "小猪图片");
		} catch (Exception e) {
			System.out.println("load image error");
		}

		mainForm.append(pngItem_1);
		mainForm.append(pngItem_2);

		mainForm.addCommand(exitCommand);
		mainForm.setCommandListener(this);

		Display.getDisplay(this).setCurrent(mainForm);
	}

	public void commandAction(Command c, Displayable s) {
		if (c == exitCommand) {
			destroyApp(false);
			notifyDestroyed();
		}
	}

	protected void destroyApp(boolean unconditional) {
	}

	protected void pauseApp() {
	}
}

⌨️ 快捷键说明

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