import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class PhotoMIDlet extends MIDlet implements CommandListener
{
String list1[]={"1","2","3"};
private Command okCommand=new Command("确定",Command.OK,1);
private Command backCommand=new Command("返回",Command.BACK,1);
private Command exitCommand=new Command("退出",Command.EXIT,1);
private List list2=new List("Photo",List.EXCLUSIVE,list1,null);
private Display display=null;
private Form form=new Form("Photo");
private Image img=null;
public PhotoMIDlet(){
list2.addCommand(okCommand);
list2.addCommand(exitCommand);
list2.addCommand(backCommand);
list2.setCommandListener(this);
form.addCommand(okCommand);
form.addCommand(exitCommand);
form.addCommand(backCommand);
form.setCommandListener(this);
}
public void startApp(){
if(display==null)
display=Display.getDisplay(this);
display.setCurrent(list2);
}
public void pauseApp(){
}
public void destroyApp(boolean unkown){
}
public void commandAction(Command cmd,Displayable dis){
if(cmd==okCommand){
int sIn=list2.getSelectedIndex();
String str=(String)list2.getString(sIn);
try{
img=Image.createImage("/"+str+".png");
}catch(Exception e){}
form.append(img);
display.setCurrent(form);
}
else if(cmd==backCommand){
form.deleteAll();
display.setCurrent(list2);
}
else if(cmd==exitCommand){
destroyApp(true);
notifyDestroyed();
}
}
}
List用法一例
No TrackBacks
TrackBack URL: http://www.wujianrong.com/mt-tb.cgi/1738


Leave a comment