RoomList.java
上传用户:haojie1228
上传日期:2022-08-08
资源大小:347k
文件大小:4k
- package poker;
- import java.io.*;
- import java.util.*;
- import javax.microedition.lcdui.*;
- import javax.microedition.lcdui.Command;
- public class RoomList implements CommandListener{
- /** Constructor */
- Timer one;
- MyTask oneTask;
- String[] imID=new String[20];
- List imList,tempList;
- int imListSelected=0;
- Command exitCmd,okCmd,downCmd,cancelCmd,helpCmd,closeCmd;
- static RoomList _instance;
- static synchronized public RoomList getInstance() {
- if (_instance == null) {
- _instance = new RoomList();
- }
- return _instance;
- }
- public RoomList() {
- //super("RoomList");
- try {
- jbInit();
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- }
- private void jbInit(){
- GameInfo.waitFinished=false;
- imList=new List("Room list:",List.IMPLICIT);
- tempList=new List("TempRoomList",List.IMPLICIT);
- exitCmd=new Command("exit",Command.EXIT,1);
- okCmd=new Command("go on",Command.OK,1);
- cancelCmd=new Command("Cancel me",Command.CANCEL,1);
- helpCmd=new Command("Help me",Command.HELP,1);
- imList.setCommandListener(this);
- imList.addCommand(exitCmd);
- imList.addCommand(helpCmd);
- imList.addCommand(okCmd);
- imList.addCommand(cancelCmd);
- }
- public void downLoad() {
- Error.errCode=0;
- one=new Timer();
- oneTask=new MyTask();
- GameInfo.waitFinished=false;
- downLoadList();
- if (Error.errCode>0)
- {
- Func.MsgBox.setType(AlertType.ERROR);
- Func.MsgBox.setTimeout(5000);
- Func.MsgBox.setString(Error.errStr);
- GameInfo.display.setCurrent(Func.MsgBox,imList);
- Error.errCode=0;
- ServersList server=ServersList.getInstance();
- GameInfo.display.setCurrent(server.imList);
- }
- }//end class
- private void downLoadList(){
- GetServicData.imList=imList;
- GetServicData.imID=imID;
- one.schedule(oneTask,1,1000);
- return;
- }
- class MyTask extends TimerTask{
- public void run() {
- downLoadTask();
- }
- }
- private void downLoadTask(){
- String s1="";
- String s2="";
- int ss=imList.getSelectedIndex();
- GetServicData.url = "http://"+GameInfo.ServerAddress
- + "/gameservice/infomationservice.asmx/GetPlayRoomList?gameID="
- + GameInfo.GameID;
- GetServicData.kind=2;
- imListSelected=imList.getSelectedIndex();
- GetServicData.imList=tempList;
- GetServicData.imID=imID;
- //DataAccess da=DataAccess.getInstance();
- //da.getRoomList();
- GetServicData.connect();
- int imListSize=imList.size();
- int tempListSize=tempList.size();
- int xx=tempListSize-imListSize;
- if (ss>(tempListSize-1)) {ss=tempListSize-1;}
- for (int i=1;i<=xx;i++){
- imList.append("ii",GetServicData.RoomImage);
- }
- for (int i=0;i<tempListSize;i++){
- s1=tempList.getString(i);
- s2=imList.getString(i);
- if (s1!=s2){
- imList.set(i,"_"+s1,GetServicData.RoomImage);
- }
- }
- if (ss>=0){
- imList.setSelectedIndex(ss,true);
- }
- System.out.println("imList selected :"+ss);
- GameInfo.display.setCurrent(imList);
- System.out.println("do once.");
- }
- public void commandAction(Command c, Displayable d) {
- if (c==okCmd){
- int ss=imList.getSelectedIndex();
- GameInfo.RoomID=imID[ss+1];
- TableList tableList=TableList.getInstance();
- GameInfo.waitFinished=false;
- GameInfo.display.setCurrent(Func.waitForm);
- tableList.downLoad();
- one.cancel();
- _instance=null;
- }
- }
- }