资源描述:
《j2me手机游戏设计案例源代码-testlist》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、*********TestListMID/**Tochangethistemplate,chooseTools
2、Templates*andopenthetemplateintheeditor.*/importjavax.microedition.lcdui.Choice;importjavax.microedition.lcdui.Command;importjavax.microedition.lcdui.CommandListener;importjavax.microedition.lcdui.Display;importjavax
3、.microedition.lcdui.Displayable;importjavax.microedition.lcdui.Image;importjavax.microedition.lcdui.List;importjavax.microedition.midlet.*;/***@authorAdministrator*/publicclassTestListMIDextendsMIDletimplementsCommandListener{//这里注意如何使用//CommandListener这个接口privatefinalsta
4、ticCommandCMD_EXIT=newCommand("Exit",Command.EXIT,1);privatefinalstaticCommandCMD_BACK=newCommand("Back",Command.BACK,1);privateDisplaydisplay;privateListmainList;privateListexclusiveList;privateListimplicitList;privateListmultipleList;privatebooleanfirstTime;Image[]image
5、Array=null;publicTestListMID(){display=Display.getDisplay(this);String[]stringArray={"选项A","选项B","选项C","选项D"};//待传入进行初始化的String数组,即Choice选项的文字部分。//这里只是为Image[]数组进行初始化。exclusiveList=newList("Exclusive",Choice.EXCLUSIVE,stringArray,imageArray);exclusiveList.addCommand(CMD_B
6、ACK);exclusiveList.addCommand(CMD_EXIT);exclusiveList.setCommandListener(this);//ExlcusiveList的声明implicitList=newList("Implicit",Choice.IMPLICIT,stringArray,imageArray);implicitList.addCommand(CMD_BACK);implicitList.addCommand(CMD_EXIT);implicitList.setCommandListener(thi
7、s);//ImplicitList的声明multipleList=newList("Multiple",Choice.MULTIPLE,stringArray,imageArray);multipleList.addCommand(CMD_BACK);multipleList.addCommand(CMD_EXIT);multipleList.setCommandListener(this);//MutipleList的声明firstTime=true;}protectedvoidstartApp(){if(firstTime)image
8、Array=null;try{Imageicon=Image.createImage("/Icon.png");//注意!这里的路径是相对路径,请大家千万注意这里的细节问题imageArray=newImage[]{icon,icon,icon};}catch(java.io.IOExceptionerr){//ignoretheimageloadingfailuretheapplicationcanrecover.}String[]stringArray={"Exclusive","Implicit","Multiple"};mainL
9、ist=newList("Choosetype",Choice.IMPLICIT,stringArray,imageArray);mainList.addCommand(CMD_EXIT);m