程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> J2ME >> 我的J2ME編程聯系(1)——List

我的J2ME編程聯系(1)——List

編輯:J2ME
  
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);
                
                        
                }
                
                
  
 }
   
 
 
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved