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

📄 dialog.java

📁 《精通JAVA手机游戏与应用程序设计》随书光盘
💻 JAVA
字号:

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



public class Dialog extends Form implements CommandListener {
	Display display;

	DialogListener dll;

	Displayable parent;

	public static final int OK = 1;

	public static final int YES = 2;

	public static final int NO = 4;

	public static final int CANCEL = 8;

	public static final int CONFIRM = 16;

	Command cmOK;

	Command cmYES;

	Command cmNO;

	Command cmCANCEL;

	Command cmCONFIRM;

	StringItem text;

	public Dialog(String title, String text, int mode, MIDlet midlet,
			DialogListener dll, Displayable dis) {
		super(title);
		this.dll = dll;
		this.text = new StringItem(null, text);
		this.display = Display.getDisplay(midlet);
		this.parent = dis;

		if ((mode & OK) != 0) {
			cmOK = new Command("确定", Command.OK, 1);
			addCommand(cmOK);
		}
		if ((mode & YES) != 0) {
			cmYES = new Command("是", Command.OK, 1);
			addCommand(cmYES);
		}
		if ((mode & CANCEL) != 0) {
			cmCANCEL = new Command("取消", Command.CANCEL, 1);
			addCommand(cmCANCEL);
		}
		if ((mode & CONFIRM) != 0) {
			cmCONFIRM = new Command("应用", Command.SCREEN, 1);
			addCommand(cmCONFIRM);
		}
		if ((mode & NO) != 0) {
			cmNO = new Command("否", Command.EXIT, 1);
			addCommand(cmNO);
		}
		append(text);
		setCommandListener(this);
	}

	public void commandAction(Command c, Displayable s) {
		if (dll != null) {
			if (c == cmOK)
				dll.onOK();
			else if (c == cmYES)
				dll.onYES();
			else if (c == cmNO)
				dll.onNO();
			else if (c == cmCANCEL)
				dll.onCANCELK();
			else if (c == cmCONFIRM)
				dll.onCONFOIRM();

		}
		display.setCurrent(parent);
	}

}

⌨️ 快捷键说明

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