TableList.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. /**
  7.  * <p>Title: </p>
  8.  * <p>Description: </p>
  9.  * <p>Copyright: Copyright (c) 2004</p>
  10.  * <p>Company: </p>
  11.  * @author not attributable
  12.  * @version 1.0
  13.  */
  14. public class TableList implements CommandListener{
  15.   Timer one;
  16.   MyTask oneTask;
  17.   String[] imID=new String[20];
  18.   List imList,tempList;
  19.   int imListSelected=0;
  20.   int i=0;
  21.   static TableList _instance;
  22.   Command exitCmd,okCmd,downCmd,cancelCmd,helpCmd,closeCmd;
  23.  static synchronized public TableList getInstance() {
  24.     if (_instance == null) {
  25.       _instance = new TableList();
  26.     }
  27.     return _instance;
  28.   }
  29.   public TableList() {
  30.     GameInfo.waitFinished=false;
  31.     imList=new List("Table list:",List.IMPLICIT);
  32.     tempList=new List("temp list:",List.IMPLICIT);
  33.     exitCmd=new Command("exit",Command.EXIT,1);
  34.     okCmd=new Command("go on",Command.OK,1);
  35.     cancelCmd=new Command("Cancel me",Command.CANCEL,1);
  36.     closeCmd=new Command("close me",Command.EXIT,1);
  37.     downCmd=new Command("download new servers list",Command.SCREEN,2);
  38.     helpCmd=new Command("Help me",Command.HELP,1);
  39.     imList.setCommandListener(this);
  40.     imList.addCommand(exitCmd);
  41.     imList.addCommand(helpCmd);
  42.     imList.addCommand(okCmd);
  43.     imList.addCommand(cancelCmd);
  44.     imList.addCommand(closeCmd);
  45.   }
  46.   class MyTask extends TimerTask{
  47.     public void run() {
  48.      //create a new Thread
  49.      Connect connectThread=new Connect();
  50.      connectThread.start();
  51.     }
  52.   }
  53.   public void downLoad(){
  54.     Error.errCode=0;
  55.     one=new Timer();
  56.     oneTask=new MyTask();
  57.     //GameInfo.display.setCurrent(Func.waitForm);
  58.     GameInfo.waitFinished=false;
  59.     GetServicData.imList=imList;
  60.     GetServicData.imID=imID;
  61.     one.schedule(oneTask,1,1000);
  62.   return;
  63. }
  64.   private void downLoadTask(){
  65.     String s1="";
  66.     String s2="";
  67.     GetServicData.url = "http://"+GameInfo.ServerAddress
  68.                       + "/gameservice/infomationservice.asmx/GetPlayTableList?gameID="
  69.                       + GameInfo.GameID+"&roomID="+GameInfo.RoomID;
  70.     GetServicData.kind=3;
  71.     System.out.println(GetServicData.url);
  72.     int ss=imList.getSelectedIndex();
  73.     GetServicData.imList=tempList;
  74.     GetServicData.imID=imID;
  75.     GetServicData.connect();
  76.         int imListSize=imList.size();
  77.         int tempListSize=tempList.size();
  78.         int xx=tempListSize-imListSize;
  79.         if (ss>(tempListSize-1)) {ss=tempListSize-1;}
  80.         for (int i=1;i<=xx;i++){
  81.           imList.append("ii",GetServicData.TableImage);
  82.         }
  83.         for (int i=0;i<tempListSize;i++){
  84.           s1=tempList.getString(i);
  85.           s2=imList.getString(i);
  86.           if (s1!=s2){
  87.             imList.set(i,"_"+s1,GetServicData.TableImage);
  88.           }
  89.         }
  90.         if (ss>=0){
  91.           imList.setSelectedIndex(ss,true);
  92.         }
  93.           GameInfo.display.setCurrent(imList);
  94.     System.out.println("do table list once."+(i++));
  95.   }
  96.   public void commandAction(Command c, Displayable d) {
  97.     if (c==cancelCmd){
  98.       RoomList room=RoomList.getInstance();
  99.       GameInfo.display.setCurrent(Func.waitForm);
  100.       room.downLoad();
  101.       one.cancel();
  102.       _instance=null;
  103.     }
  104.     if (c==okCmd){
  105.       one.cancel();
  106.       int TableIndex=imList.getSelectedIndex();
  107.       GameInfo.TableID=imID[TableIndex+1].toString();
  108.       System.out.println("table ID="+GameInfo.TableID);
  109.       _instance=null;
  110.       WaitPlayer ww=WaitPlayer.getInstance();
  111.       GameInfo.display.setCurrent(ww.waitPlayerCanvas);
  112.       ww.waiting();
  113.     }
  114.   }
  115.   class Connect extends Thread {
  116.     public void run() {
  117.        downLoadTask();
  118.     }
  119.   }
  120. }