日本a√视频在线,久久青青亚洲国产,亚洲一区欧美二区,免费g片在线观看网站

        <style id="k3y6c"><u id="k3y6c"></u></style>
        <s id="k3y6c"></s>
        <mark id="k3y6c"></mark>
          
          

          <mark id="k3y6c"></mark>

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 開(kāi)發(fā)MIDP聯(lián)網(wǎng)應(yīng)用程序

          開(kāi)發(fā)MIDP聯(lián)網(wǎng)應(yīng)用程序

          作者: 時(shí)間:2012-05-07 來(lái)源:網(wǎng)絡(luò) 收藏

          為在通過(guò)游戲時(shí)顯示最高分,要與服務(wù)器進(jìn)行通信,由此獲得最高分。這里,可以用我們介紹的HttpConnection,利用GET取得最高分??梢栽谟螒蚪Y(jié)束時(shí)使用以下方法。

          /**

          *與服務(wù)器進(jìn)行通信,獲取最高分。

          */

          publicString[]getHighScore(){

          String[]str=newString[5];

          HttpConnectioncon=null;

          DataInputStreamin=null;

          try{

          con=(HttpConnection)Connector.open(SERVER_URL);

          //接收response

          in=con.openDataInputStream();

          intinput;

          inti=0;

          Strings=;

          while((input=in.read())!=-1){

          if((char)input=='n'){

          str[i]=s;

          i++;

          s=;

          continue;

          }

          s=s+(char)input;

          }

          }catch(IOExceptione){

          e.printStackTrace();

          }finally{

          if(con!=null){

          try{

          con.close();

          }catch(IOExceptione1){

          e1.printStackTrace();

          }

          }

          if(in!=null){

          try{

          in.close();

          }catch(IOExceptione1){

          e1.printStackTrace();

          }

          }

          }

          returnstr;

          }

          ex.12

          下面是進(jìn)行游戲時(shí)的操作。結(jié)束游戲時(shí)向服務(wù)器發(fā)送結(jié)束時(shí)間,即利用POST如下所示發(fā)送結(jié)束時(shí)間。然后,接收來(lái)自服務(wù)器的response最高分??梢栽谟螒蚪Y(jié)束時(shí)使用以下方法。

          /**

          *向服務(wù)器發(fā)送時(shí)間表,取得最高分

          */

          publicString[]sendScore(){

          String[]str=newString[5];

          HttpConnectioncon=null;

          DataOutputStreamout=null;

          DataInputStreamin=null;

          try{

          con=(HttpConnection)Connector.open(SERVER_URL);

          con.setRequestMethod(HttpConnection.POST);

          out=con.openDataOutputStream();

          //向服務(wù)器發(fā)送時(shí)間表

          Stringmessage=score=+second;

          byte[]messageByte=message.getBytes();

          for(inti=0;i

          out.writeByte(messageByte[i]);

          }

          out.close();

          //接收response

          in=con.openDataInputStream();

          intinput;

          inti=0;

          Strings=;

          while((input=in.read())!=-1){

          if((char)input=='n'){

          str[i]=s;

          i++;

          s=;

          continue;

          }

          s=s+(char)input;

          }

          }catch(IOExceptione){

          e.printStackTrace();

          }finally{

          if(con!=null){

          try{

          con.close();

          }catch(IOExceptione1){

          e1.printStackTrace();

          }

          }

          if(out!=null){

          try{

          out.close();

          }catch(IOExceptione1){

          e1.printStackTrace();

          }

          }

          if(in!=null){

          try{

          in.close();

          }catch(IOExceptione1){

          e1.printStackTrace();

          }

          }

          }

          returnstr;

          }

          ex.13

          2.3.顯示最高分

          通過(guò)游戲和游戲結(jié)束時(shí),都顯示最高分。用以下方法顯示最高分:

          /**

          *顯示最高分

          */

          publicvoidpaintHighScore(Graphicsg){

          for(inti=0;i

          if(highscore[i]==null)break;

          g.drawString(

          highscore[i],

          10,

          10+i*15,

          Graphics.LEFT|Graphics.TOP);

          }

          }

          ex.14

          2.4.運(yùn)行

          完成的sourcecode如下:

          •BlockApplication.java

          •BlockCanvas.java

          另外,服務(wù)器使用的SERVLET的sourcecode式如下:

          •nec_server.zip

          運(yùn)行后的結(jié)果如下:

          3.總結(jié)

          本講中,介紹了可以利用HTTP通信進(jìn)行網(wǎng)絡(luò)編程。利用本講介紹的東西,能夠制作簡(jiǎn)單的chat程序以及作戰(zhàn)游戲等。請(qǐng)大家也試著制作一些新的獨(dú)特的吧。


          上一頁(yè) 1 2 3 4 下一頁(yè)

          評(píng)論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉