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

📄 dialogtest.java

📁 java就业培训教程第五章实例
💻 JAVA
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class DialogTest extends MIDlet implements CommandListener, DialogListener{

	Display display;
	Dialog confirmDialog;
	List itemList;
	Command exitCmd;
	Command okCmd;
	Command backCmd;
	TextBox editor;
	Alert info;
	Ticker news;

	public DialogTest(){
		display = Display.getDisplay(this);
		confirmDialog = new Dialog("信息","确定","取消");
		editor = new TextBox("请输入信用卡号","",16, TextField.NUMERIC|TextField.PASSWORD);
		info = new Alert("","谢谢您,欢迎您继续选购!",null,AlertType.INFO);
		itemList = new List("选择要购买的东西",List.MULTIPLE);
		news = new Ticker("跳楼大拍卖");
		exitCmd = new Command("退出", Command.EXIT, 1);
		okCmd = new Command("完成", Command.OK, 1);
		backCmd = new Command("返回", Command.BACK, 1);
		itemList.append("铅笔",null);
		itemList.append("背包",null);
		itemList.append("书本",null);
		itemList.addCommand(exitCmd);
		itemList.addCommand(okCmd);
		itemList.setTicker(news);
		itemList.setCommandListener(this);
		editor.addCommand(backCmd);
		editor.addCommand(okCmd);
		editor.setCommandListener(this);
		confirmDialog.setDialogListener(this);
	}


	public void startApp(){
		display.setCurrent(itemList);
	}

	public void pauseApp(){

	}

	public void destroyApp(boolean unconditional){

	}

	public void commandAction(Command c,Displayable d){

		if(c == exitCmd){
			destroyApp(false);
			notifyDestroyed();
		}
		else if(c == okCmd){
			if(display.getCurrent() == itemList){
				display.setCurrent(editor);
			}
			else if(display.getCurrent() == editor){
				confirmDialog.setText("您购买了下列商品\n");
				for(int i = 0; i< itemList.size();i++){
					if(itemList.isSelected(i)){
						confirmDialog.setText(itemList.getString(i)+"\n");
					}
				}
				confirmDialog.setText("\n确定了吗?");
				confirmDialog.showDialog(display);
			}

		}
		else if(c == backCmd){
			display.setCurrent(itemList);
		}
	}

	public void process(int code){

		if(code == Dialog.LEFT){
			display.setCurrent(info, itemList);
		}
		else if(code == Dialog.RIGHT){
			display.setCurrent(itemList);

		}
	}

}

⌨️ 快捷键说明

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