dialogdemo.java

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

JAVA
54
字号
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class DialogDemo extends MIDlet implements CommandListener {

	private Command exitCommand;

	private TextBox tb;
	public DialogDemo() {
		exitCommand = new Command("退出程序", Command.EXIT, 1);
		tb = new TextBox("对话框演示程序", "显示退出程序提醒对话框", 15, 0);
		tb.addCommand(exitCommand);
		tb.setCommandListener(this);
	}

	
	protected void startApp(){		
		Display.getDisplay(this).setCurrent(tb);
	}
	
	protected void pauseApp() {
	
	}

	protected void destroyApp(boolean arg0){
		
	}
	public void commandAction(Command c, Displayable d) {
		if (c == exitCommand) {
			
			DialogListener dllistener =new DialogListener(){
				//实现具体的操作
				public void onCONFOIRM(){
					//退出程序
					System.out.println("exit");
					destroyApp(false);			
					notifyDestroyed();
				}
				public void onCANCELK(){	
					System.out.println("cancel");
					
				}
				
			};
			Dialog dl = new Dialog("提示","确定需要关闭程序吗?",
					Dialog.CANCEL|Dialog.CONFIRM,this,dllistener,tb);
			Display.getDisplay(this).setCurrent(dl);
		}

	}
	
}

⌨️ 快捷键说明

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