RoomList.java
上传用户:haojie1228
上传日期:2022-08-08
资源大小:347k
文件大小:4k
源码类别:

通讯/手机编程

开发平台:

Java

  1. package poker;
  2. import java.io.*;
  3. import java.util.*;
  4. import javax.microedition.lcdui.*;
  5. import javax.microedition.lcdui.Command;
  6. public class RoomList implements CommandListener{
  7.   /** Constructor */
  8.   Timer one;
  9.   MyTask oneTask;
  10.   String[] imID=new String[20];
  11.   List imList,tempList;
  12.   int imListSelected=0;
  13.   Command exitCmd,okCmd,downCmd,cancelCmd,helpCmd,closeCmd;
  14.   static RoomList _instance;
  15.   static synchronized public RoomList getInstance() {
  16.     if (_instance == null) {
  17.       _instance = new RoomList();
  18.     }
  19.     return _instance;
  20.   }
  21.   public RoomList() {
  22.     //super("RoomList");
  23.     try {
  24.       jbInit();
  25.     }
  26.     catch(Exception e) {
  27.       e.printStackTrace();
  28.     }
  29.   }
  30.   private void jbInit(){
  31.     GameInfo.waitFinished=false;
  32.     imList=new List("Room list:",List.IMPLICIT);
  33.     tempList=new List("TempRoomList",List.IMPLICIT);
  34.     exitCmd=new Command("exit",Command.EXIT,1);
  35.     okCmd=new Command("go on",Command.OK,1);
  36.     cancelCmd=new Command("Cancel me",Command.CANCEL,1);
  37.     helpCmd=new Command("Help me",Command.HELP,1);
  38.     imList.setCommandListener(this);
  39.     imList.addCommand(exitCmd);
  40.     imList.addCommand(helpCmd);
  41.     imList.addCommand(okCmd);
  42.     imList.addCommand(cancelCmd);
  43.   }
  44.   public void downLoad() {
  45.     Error.errCode=0;
  46.     one=new Timer();
  47.     oneTask=new MyTask();
  48.     GameInfo.waitFinished=false;
  49.     downLoadList();
  50.     if (Error.errCode>0)
  51.     {
  52.       Func.MsgBox.setType(AlertType.ERROR);
  53.       Func.MsgBox.setTimeout(5000);
  54.       Func.MsgBox.setString(Error.errStr);
  55.       GameInfo.display.setCurrent(Func.MsgBox,imList);
  56.       Error.errCode=0;
  57.       ServersList server=ServersList.getInstance();
  58.       GameInfo.display.setCurrent(server.imList);
  59.     }
  60.   }//end class
  61.   private void downLoadList(){
  62.     GetServicData.imList=imList;
  63.     GetServicData.imID=imID;
  64.     one.schedule(oneTask,1,1000);
  65.     return;
  66.   }
  67.   class MyTask extends TimerTask{
  68.     public void run() {
  69.       downLoadTask();
  70.     }
  71.   }
  72.   private void downLoadTask(){
  73.     String s1="";
  74.     String s2="";
  75.     int ss=imList.getSelectedIndex();
  76.     GetServicData.url = "http://"+GameInfo.ServerAddress
  77.                       + "/gameservice/infomationservice.asmx/GetPlayRoomList?gameID="
  78.                       + GameInfo.GameID;
  79.     GetServicData.kind=2;
  80.     imListSelected=imList.getSelectedIndex();
  81.     GetServicData.imList=tempList;
  82.     GetServicData.imID=imID;
  83.     //DataAccess da=DataAccess.getInstance();
  84.     //da.getRoomList();
  85.     GetServicData.connect();
  86.     int imListSize=imList.size();
  87.     int tempListSize=tempList.size();
  88.     int xx=tempListSize-imListSize;
  89.     if (ss>(tempListSize-1)) {ss=tempListSize-1;}
  90.     for (int i=1;i<=xx;i++){
  91.       imList.append("ii",GetServicData.RoomImage);
  92.     }
  93.     for (int i=0;i<tempListSize;i++){
  94.       s1=tempList.getString(i);
  95.       s2=imList.getString(i);
  96.       if (s1!=s2){
  97.         imList.set(i,"_"+s1,GetServicData.RoomImage);
  98.       }
  99.     }
  100.     if (ss>=0){
  101.       imList.setSelectedIndex(ss,true);
  102.     }
  103.     System.out.println("imList selected :"+ss);
  104.     GameInfo.display.setCurrent(imList);
  105.     System.out.println("do once.");
  106.   }
  107.   public void commandAction(Command c, Displayable d) {
  108.     if (c==okCmd){
  109.       int ss=imList.getSelectedIndex();
  110.       GameInfo.RoomID=imID[ss+1];
  111.       TableList tableList=TableList.getInstance();
  112.       GameInfo.waitFinished=false;
  113.       GameInfo.display.setCurrent(Func.waitForm);
  114.       tableList.downLoad();
  115.       one.cancel();
  116.       _instance=null;
  117.     }
  118.   }
  119. }