欢迎光临
我们一直在努力

我的J2ME编程联系(1)——List-JSP教程,J2ME开发

建站超值云服务器,限时71元/月

  

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);

                

                        

                }

                

                

  

 }

   

 

 

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 我的J2ME编程联系(1)——List-JSP教程,J2ME开发
分享到: 更多 (0)