俺写的第一个javame程序,纪念一下

/*
* ListTestMidlet.java
*
* Created on 2007年10月10日, 下午3:13
*用来测试对List对象的理解
*/

package com.hf.javame.commonTest.list;

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

/**
*
* @author Administrator
* @version
*/
public class ListTestMidlet extends MIDlet implements CommandListener {
/**
*当前midlet的Display对象引用
*/
private Display display = null;
private List impList = null;
/*多选列表*/
private List mutilist=null;
/* 单选列表*/
private List siglist=null;
/**
*定义退出命令
*/
private Command exitCommand=new Command("退出",Command.EXIT,1);
private Command selectCommand=new Command("选择",Command.SCREEN,1);
private Command returnCommand=new Command("返回类型列表",Command.ITEM,2);
private Command alertCommand = new Command("查看选择结果",Command.ITEM,1);
/**
*构造函数
*/
public ListTestMidlet (){
/**
*给引用赋予值
*/
display = Display.getDisplay(this);

/**
*生成命令列表
*/
impList=new List("请选择一种列表进行操作展示",Choice.IMPLICIT);
impList.append("多选列表",null);
impList.append("单选列表",null);
impList.addCommand(selectCommand);
impList.addCommand(exitCommand);
/*设置命令监听器*/
impList.setCommandListener(this);


/**
*生成多选列表
*
*/
mutilist=new List("城市选择",Choice.MULTIPLE);
mutilist.append("济南",null);
mutilist.append("上海",null);
mutilist.append("北京",null);
mutilist.setCommandListener(this);
mutilist.addCommand(alertCommand);
mutilist.addCommand(returnCommand);
/**
*生成单选列表
*
*/
siglist=new List("城市选择",Choice.EXCLUSIVE);
siglist.append("济南",null);
siglist.append("上海",null);
siglist.append("北京",null);
siglist.setCommandListener(this);
siglist.addCommand(alertCommand);
siglist.addCommand(returnCommand);


}
/*进入启动状态时被调用,载入impList对象*/
public void startApp() {
display.setCurrent(impList);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

public void commandAction(Command command, Displayable displayable) {

if(command == exitCommand){
//退出应用程序
destroyApp(false);
notifyDestroyed();
}

if(command==selectCommand){
List list=(List)displayable;
String value= list.getString(list.getSelectedIndex());
if("多选列表".equals(value)){
this.display.setCurrent(this.mutilist);
}
else
if("单选列表".equals(value)){
this.display.setCurrent(this.siglist);
}
// this.display.setCurrent(alert);
}
if(command==returnCommand){

this.display.setCurrent(this.impList);
}
if(command==alertCommand){
List list=(List)displayable;

String disValue="";
for(int i=0;i<list.size();i++){
if(list.isSelected(i)){
disValue+=list.getString(i);
}
}
Alert alert=new Alert("您选择了:"+disValue,"",null,AlertType.INFO);
alert.setTimeout(4000);
this.display.setCurrent(alert);

}



}
}

你可能感兴趣的:(JavaME)