我的J2ME编程联系(1)——List

2008-02-23 09:55:12来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

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

public class listtest extends MIDlet implements CommandListener{

private List alist;
private Command exitcommand;
private Command okcommand;
private Display adisplay;
private Alert analert;


public listtest(){
analert=new Alert("Selected","You have Choose a Fruit",null,AlertType.INFO);

alist=new List("fruit",Choice.MULTIPLE);
exitcommand=new Command("Exit",Command.EXIT,1);
okcommand=new Command("OK",Command.OK,1);

alist.append("Apple",null);
alist.append("Orange",null);
alist.append("banana",null);

alist.addCommand(exitcommand);
alist.addCommand(okcommand);

alist.setCommandListener(this);
}

public void startApp(){

adisplay=Display.getDisplay(this);
adisplay.setCurrent(alist);

}

public void pauseApp(){

}

public void destroyApp(boolean unconditional){

}

public void commandAction(Command c,Displayable d){
// use the i get the Selected list element
//int i =alist.getSelectedIndex();

if(c==exitcommand){
destroyApp(false);
notifyDestroyed();

}

else {
//display different information when diffenent element
//have been selected
/*if(i==0){
analert.setString("You have Choosed Apple!");
adisplay.setCurrent(analert,alist);
}

if(i==1){
analert.setString("You have Choosed Orange!");
adisplay.setCurrent(analert,alist);
}

if(i==2){
analert.setString("You have Choosed Banana!");
adisplay.setCurrent(analert,alist);
}*/
String s=" ";
for(int i=0;i<alist.size();i ){

boolean selected=alist.isSelected(i);
if(selected&&i==0){
s ="Apple ";
}

if(selected&&i==1){
s ="Orange ";
}

if(selected&&i==2){
s ="Banana ";
}
}

analert.setString("You have Selected" s);
analert.setTimeout(Alert.FOREVER);
adisplay.setCurrent(analert,alist);


}



}



}

上一篇: 我的J2ME编程联系(2)——DateField
下一篇: 《Java 手机/PDA 程序设计入门》读书笔记11-- MIDP数据库设计1

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:一个用数据库实现的工作流

下一篇:jsp连接mysql 并正常显示中文