中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. 新聞中心

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

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

        作者: 時間:2012-05-07 來源:網(wǎng)絡 收藏

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

        /**

        *與服務器進行通信,獲取最高分。

        */

        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

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

        /**

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

        */

        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();

        //向服務器發(fā)送時間表

        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.顯示最高分

        通過游戲和游戲結束時,都顯示最高分。用以下方法顯示最高分:

        /**

        *顯示最高分

        */

        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.運行

        完成的sourcecode如下:

        •BlockApplication.java

        •BlockCanvas.java

        另外,服務器使用的SERVLET的sourcecode式如下:

        •nec_server.zip

        運行后的結果如下:

        3.總結

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


        上一頁 1 2 3 4 下一頁

        評論


        相關推薦

        技術專區(qū)

        關閉