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

通讯/手机编程

开发平台:

Java

  1. package poker;
  2. import com.nokia.mid.ui.*;
  3. import javax.microedition.lcdui.*;
  4. import javax.microedition.lcdui.Canvas;
  5. import java.io.*;
  6. import java.util.*;
  7. import javax.microedition.lcdui.Graphics;
  8. import javax.microedition.lcdui.Command;
  9. import javax.microedition.lcdui.Displayable;
  10. /**
  11.  * <p>Title: </p>
  12.  * <p>Description: </p>
  13.  * <p>Copyright: Copyright (c) 2004</p>
  14.  * <p>Company: </p>
  15.  * @author not attributable
  16.  * @version 1.0
  17.  */
  18. public class WaitPlayer  {
  19.   Image backImage,whoImage,manImage,womanImage,exitButtonImage,dotImage;
  20.   int N=0;
  21.   Timer one,listSeatTimer;
  22.   MyTask oneTask;
  23.   ListSeatTask listSeatTask;
  24.   TableList tableList;
  25.   WaitPlayerCanvas waitPlayerCanvas;
  26.   String Account1,Account2,Account3;
  27.   String seatID1,seatID2,seatID3;
  28.   static WaitPlayer _instance;
  29.   static synchronized public WaitPlayer getInstance() {
  30.     if (_instance == null) {
  31.       _instance = new WaitPlayer();
  32.     }
  33.     return _instance;
  34.   }
  35.   public WaitPlayer() {
  36.     try {
  37.         backImage = Image.createImage("/res/back1.gif");
  38.         whoImage=Image.createImage("/res/w1_m1.gif");
  39.         manImage=Image.createImage("/res/w1_m3.gif");
  40.         womanImage=Image.createImage("/res/w1_m2.gif");
  41.         exitButtonImage=Image.createImage("/res/exitbutton.gif");
  42.         dotImage = Image.createImage("/res/dot.gif");
  43.       }
  44.       catch (IOException ex) {
  45.       }
  46.       one=new Timer();
  47.       oneTask=new MyTask();
  48.       waitPlayerCanvas=new WaitPlayerCanvas();
  49.     }
  50.  public void waiting(){
  51.    one.schedule(oneTask,1,100);//draw dot
  52.    /* send "I want a seat message " to server,
  53.     * replay:can(0) can't(-1)
  54.     *
  55.     */
  56.    CanSit canSitThread=new CanSit();
  57.    canSitThread.start();
  58.  }
  59.   class MyTask extends TimerTask{
  60.     public void run() {
  61.       waitPlayerCanvas.repaint();
  62.     }
  63.   }
  64.   class ListSeatTask extends TimerTask{
  65.     public void run(){
  66.       GetServicData.getSeat();
  67.       // GetServicData.imID --->sex
  68.       // GetServicData.imValue --->AccountName
  69.       Account1=GetServicData.imValue[1];
  70.       Account2=GetServicData.imValue[2];
  71.       Account3=GetServicData.imValue[3];
  72.       seatID1=GetServicData.imID[1];
  73.       seatID2=GetServicData.imID[2];
  74.       seatID3=GetServicData.imID[3];
  75.     }
  76.   }
  77.   class  CanSit extends Thread {
  78.     String result="";
  79.     public void run(){
  80.       result = GetServicData.getIfCanSit();
  81.       if (result!="-1"){
  82.         listSeatTimer=new Timer();
  83.         listSeatTask=new ListSeatTask();
  84.         listSeatTimer.schedule(listSeatTask,1,1000);
  85.       }else{
  86.         Func.MsgBox.setString("sit Full when your request arrived or something cause your request failed!please choose another seat and try again.");
  87.         Func.MsgBox.setTitle("you can't sit this seat!");
  88.         Func.MsgBox.setTimeout(4000);
  89.         Func.MsgBox.setType(AlertType.ERROR);
  90.         one.cancel();
  91.         listSeatTimer.cancel();
  92.         _instance=null;
  93.         TableList tableList=TableList.getInstance();
  94.         GameInfo.display.setCurrent(Func.MsgBox);
  95.         tableList.downLoad();
  96.       }
  97.     }
  98.   }
  99.   class WaitPlayerCanvas extends FullCanvas implements CommandListener{
  100.     protected void paint(Graphics g) {
  101.       g.drawImage(backImage,0,0,Graphics.TOP|Graphics.LEFT);
  102.       g.drawImage(manImage,0,40,Graphics.TOP|Graphics.LEFT);
  103.       g.drawImage(womanImage,58,22,Graphics.TOP|Graphics.LEFT);
  104.       g.drawImage(whoImage,122,40,Graphics.TOP|Graphics.LEFT);
  105.       g.drawImage(exitButtonImage,134,187,Graphics.TOP|Graphics.LEFT);
  106.       for (int i=0;i<N;++i){
  107.         g.drawImage(dotImage, (10+i*10), 192, Graphics.TOP | Graphics.LEFT);
  108.       }
  109.       N++;
  110.       if(N==10) {N=0;}
  111.     }
  112.     public void keyPressed(int keyCode){
  113.       System.out.println("you press:"+keyCode);
  114.       if (keyCode==-7){
  115.       }
  116.     }
  117.     public void commandAction(Command command, Displayable displayable) {
  118.     }
  119.   }
  120. }