Chinaunix首页 | 论坛 | 博客
  • 博客访问: 226843
  • 博文数量: 45
  • 博客积分: 3010
  • 博客等级: 中校
  • 技术积分: 915
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-18 16:03
文章分类

全部博文(45)

文章存档

2011年(1)

2008年(44)

我的朋友

分类: Java

2008-04-01 17:48:15

 

package j2me.study;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class ListDemo extends MIDlet implements CommandListener {
 private final static Command CMD_EXIT= new Command("Exit",Command.EXIT,1);
 private final static Command CMD_BACK= new Command("Back",Command.BACK,1);
 private Display display;
 private List mainList;
 private List exclusiveList;
 private List implicitList;
 private List multipleList;
 
 private boolean firstTime;
 
 public ListDemo(){
  display = Display.getDisplay(this);
  
  String[] stringArray ={"Option A","Option B","Option C","Option D"};
  
  Image []imageArray =null;
  
  exclusiveList = new List("Exclusive",Choice.EXCLUSIVE,stringArray,imageArray);
  exclusiveList.addCommand(CMD_BACK);
  exclusiveList.addCommand(CMD_EXIT);
  exclusiveList.setCommandListener(this);
  
  implicitList = new List("Implicit",Choice.IMPLICIT,stringArray,imageArray);
  implicitList.addCommand(CMD_BACK);
  implicitList.addCommand(CMD_EXIT);
  implicitList.setCommandListener(this);
  
  multipleList = new List("Multiple",Choice.MULTIPLE,stringArray,imageArray);
  multipleList.addCommand(CMD_BACK);
  multipleList.addCommand(CMD_EXIT);
  multipleList.setCommandListener(this);
  
  firstTime = true;
 }
 protected void destroyApp(boolean arg0) {
  // TODO Auto-generated method stub

 }
 protected void pauseApp() {
  // TODO Auto-generated method stub

 }
 protected void startApp() throws MIDletStateChangeException {
  // TODO Auto-generated method stub

  if(firstTime){
   Image[] imageArray = null;
   try{
    Image icon =Image.createImage("Icon.png");
    
    imageArray = new Image[]{
      icon,
      icon,
      icon
    };
   }catch(java.io.IOException err){
   }
   String [] stringArray={
     "Exclusive",
     "Implicit",
     "Multiple"
   };
   mainList = new List("Choose type",Choice.IMPLICIT,stringArray,imageArray);
   mainList.addCommand(CMD_EXIT);
   mainList.setCommandListener(this);
   display.setCurrent(mainList);
   firstTime = false;
  }
 }
 public void commandAction(Command c, Displayable d) {
  // TODO Auto-generated method stub

  if(d.equals(mainList)){
   if(c==List.SELECT_COMMAND){
    if(d.equals(mainList)){
     switch(((List)d).getSelectedIndex()){
     case 0:
      display.setCurrent(exclusiveList);
      break;
     case 1:
      display.setCurrent(implicitList);
      break;
     case 2:
      display.setCurrent(multipleList);
      break;
     }
    }
   }
  }else{
   if(c == CMD_BACK){
    display.setCurrent(mainList);
   }
  }
  if(c==CMD_EXIT){
   destroyApp(false);
   notifyDestroyed();
  }
 }
}

 

阅读(771) | 评论(0) | 转发(0) |
0

上一篇:感恩之心

下一篇: TextBox组件应用

给主人留下些什么吧!~~