亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? tictactoeclient.java

?? tic tac toe client server
?? JAVA
字號:
// Fig. 18.9: TicTacToeClient.java
// Client that let a user play Tic-Tac-Toe with another across a network.
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import javax.swing.*;

public class TicTacToeClient extends JApplet implements Runnable {
   private JTextField idField;
   private JTextArea displayArea;
   private JPanel boardPanel, panel2;
   private Square board[][], currentSquare;
   private Socket connection;
   private DataInputStream input;
   private DataOutputStream output;
   private char myMark;
   private boolean myTurn;
   private final char X_MARK = 'X', O_MARK = 'O';

   // Set up user-interface and board
   public void init()
   {
      Container container = getContentPane();

      // set up JTextArea to display messages to user
      displayArea = new JTextArea( 4, 30 );
      displayArea.setEditable( false );
      container.add( new JScrollPane( displayArea ), BorderLayout.SOUTH );

      // set up panel for squares in board
      boardPanel = new JPanel();
      boardPanel.setLayout( new GridLayout( 3, 3, 0, 0 ) );

      // create board
      board = new Square[ 3 ][ 3 ];

      // When creating a Square, the location argument to the constructor
      // is a value from 0 to 8 indicating the position of the Square on
      // the board. Values 0, 1, and 2 are the first row, values 3, 4,
      // and 5 are the second row. Values 6, 7, and 8 are the third row.
      for ( int row = 0; row < board.length; row++ ) {

         for ( int column = 0; column < board[ row ].length; column++ ) {

            // create Square
            board[ row ][ column ] = new Square( ' ', row * 3 + column );
            boardPanel.add( board[ row ][ column ] );
         }
      }

      // textfield to display player's mark
      idField = new JTextField();
      idField.setEditable( false );
      container.add( idField, BorderLayout.NORTH );

      // set up panel to contain boardPanel (for layout purposes)
      panel2 = new JPanel();
      panel2.add( boardPanel, BorderLayout.CENTER );
      container.add( panel2, BorderLayout.CENTER );

   } // end method init

   // Make connection to server and get associated streams.
   // Start separate thread to allow this applet to
   // continually update its output in textarea display.
   public void start()
   {
      // connect to server, get streams and start outputThread
      try {

         // make connection

         connection = new Socket( getCodeBase().getHost(), 12345 );

         // get streams
         input = new DataInputStream( connection.getInputStream() );
         output = new DataOutputStream( connection.getOutputStream() );
      }

      // catch problems setting up connection and streams
      catch ( IOException ioException ) {
         ioException.printStackTrace();
      }

      // create and start output thread
      Thread outputThread = new Thread( this );
      outputThread.start();

   } // end method start

   // control thread that allows continuous update of displayArea
   public void run()
   {
      // get player's mark (X or O)
      try {
         myMark = input.readChar();

         // display player ID in event-dispatch thread
         SwingUtilities.invokeLater(
            new Runnable() {
               public void run()
               {
                  idField.setText( "You are player \"" + myMark + "\"" );
               }
            }
         );

         myTurn = ( myMark == X_MARK ? true : false );

         // receive messages sent to client and output them
         while ( true ) {
            processMessage( input.readUTF() );
         }

      } // end try

      // process problems communicating with server
      catch ( IOException ioException ) {
         ioException.printStackTrace();
      }

   }  // end method run

   // process messages received by client
   private void processMessage( String message )
   {
      // valid move occurred
      if ( message.equals( "Valid move." ) ) {
         displayMessage( "Valid move, please wait.\n" );
         setMark( currentSquare, myMark );
      }

      // invalid move occurred
      else if ( message.equals( "Invalid move, try again" ) ) {
         displayMessage( message + "\n" );
         myTurn = true;
      }

      // opponent moved
      else if ( message.equals( "Opponent moved" ) ) {

         // get move location and update board
         try {
            int location = input.readInt();
            int row = location / 3;
            int column = location % 3;

            setMark(  board[ row ][ column ],
               ( myMark == X_MARK ? O_MARK : X_MARK ) );
            displayMessage( "Opponent moved. Your turn.\n" );
            myTurn = true;

         } // end try

         // process problems communicating with server
         catch ( IOException ioException ) {
            ioException.printStackTrace();
         }

      } // end else if

      // simply display message
      else
         displayMessage( message + "\n" );

   } // end method processMessage

   // utility method called from other threads to manipulate
   // outputArea in the event-dispatch thread
   private void displayMessage( final String messageToDisplay )
   {
      // display message from event-dispatch thread of execution
      SwingUtilities.invokeLater(
         new Runnable() {  // inner class to ensure GUI updates properly

            public void run() // updates displayArea
            {
               displayArea.append( messageToDisplay );
               displayArea.setCaretPosition(
                  displayArea.getText().length() );
            }

         }  // end inner class

      ); // end call to SwingUtilities.invokeLater
   }

   // utility method to set mark on board in event-dispatch thread
   private void setMark( final Square squareToMark, final char mark )
   {
      SwingUtilities.invokeLater(
         new Runnable() {
            public void run()
            {
               squareToMark.setMark( mark );
            }
         }
      );
   }

   // send message to server indicating clicked square
   public void sendClickedSquare( int location )
   {
      if ( myTurn ) {

         // send location to server
         try {
            output.writeInt( location );
            myTurn = false;
         }

         // process problems communicating with server
         catch ( IOException ioException ) {
            ioException.printStackTrace();
         }
      }
   }

   // set current Square
   public void setCurrentSquare( Square square )
   {
      currentSquare = square;
   }

   // private inner class for the squares on the board
   private class Square extends JPanel {
      private char mark;
      private int location;

      public Square( char squareMark, int squareLocation )
      {
         mark = squareMark;
         location = squareLocation;

         addMouseListener(
            new MouseAdapter() {
               public void mouseReleased( MouseEvent e )
               {
                  setCurrentSquare( Square.this );
                  sendClickedSquare( getSquareLocation() );
               }
            }
         );

      } // end Square constructor

      // return preferred size of Square
      public Dimension getPreferredSize()
      {
         return new Dimension( 30, 30 );
      }

      // return minimum size of Square
      public Dimension getMinimumSize()
      {
         return getPreferredSize();
      }

      // set mark for Square
      public void setMark( char newMark )
      {
         mark = newMark;
         repaint();
      }

      // return Square location
      public int getSquareLocation()
      {
         return location;
      }

      // draw Square
      public void paintComponent( Graphics g )
      {
         super.paintComponent( g );

         g.drawRect( 0, 0, 29, 29 );
         g.drawString( String.valueOf( mark ), 11, 20 );
      }

   } // end inner-class Square

} // end class TicTacToeClient

/**************************************************************************
 * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and               *
 * Prentice Hall. All Rights Reserved.                                    *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 *************************************************************************/

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产成人a级片| 国产精品嫩草影院av蜜臀| 91国偷自产一区二区三区观看| 国产成人av影院| 成熟亚洲日本毛茸茸凸凹| 国产成人三级在线观看| 国产a精品视频| 成人久久久精品乱码一区二区三区| 国产电影一区二区三区| 成人综合在线观看| 99久久精品费精品国产一区二区| 99久久精品免费看国产 | 欧美日韩精品综合在线| 欧美视频精品在线观看| 欧美肥妇毛茸茸| 欧美精品一区二区三区视频| 久久久噜噜噜久久人人看| 中文字幕精品一区二区精品绿巨人| 亚洲欧洲精品一区二区三区不卡| ㊣最新国产の精品bt伙计久久| 亚洲夂夂婷婷色拍ww47 | 99久久精品国产网站| 欧洲国内综合视频| 日韩一区二区三区在线| 国产亚洲1区2区3区| 亚洲私人黄色宅男| 香港成人在线视频| 国产精品伊人色| 色综合久久88色综合天天6| 欧美日韩国产美女| 精品成人免费观看| 日韩毛片一二三区| 蜜臀av性久久久久蜜臀aⅴ流畅| 国产白丝网站精品污在线入口| 91小视频免费观看| 在线成人午夜影院| 国产精品久久久久一区二区三区共| 亚洲精品日日夜夜| 久88久久88久久久| 色婷婷av一区二区三区gif| 日韩网站在线看片你懂的| 国产精品视频观看| 丝袜脚交一区二区| 高清在线成人网| 3d动漫精品啪啪1区2区免费| 欧美高清在线精品一区| 亚洲成av人**亚洲成av**| 韩国欧美国产一区| 欧美私模裸体表演在线观看| 久久久91精品国产一区二区精品 | 精品va天堂亚洲国产| 亚洲人精品午夜| 蜜臀久久久久久久| 91麻豆国产在线观看| 久久一日本道色综合| 亚洲综合色自拍一区| 国产99久久久久| 91精品在线免费| 一区二区视频免费在线观看| 精品一区二区免费视频| 欧美综合久久久| 国产女同性恋一区二区| 日韩av在线播放中文字幕| 成人av在线资源网站| 日韩欧美国产精品| 亚洲午夜一区二区三区| 成人白浆超碰人人人人| 久久夜色精品一区| 石原莉奈在线亚洲三区| 色综合久久综合网97色综合 | 日韩av高清在线观看| 97久久精品人人澡人人爽| 久久久91精品国产一区二区三区| 日本不卡高清视频| 欧美午夜电影在线播放| 国产精品进线69影院| 国产高清在线观看免费不卡| 日韩欧美中文字幕公布| 亚洲成人精品在线观看| 97超碰欧美中文字幕| 国产日韩欧美精品在线| 国产综合一区二区| 日韩三级在线观看| 水蜜桃久久夜色精品一区的特点| 久久久久久久电影| 日韩av中文字幕一区二区| 欧美色欧美亚洲另类二区| 亚洲欧美日韩在线不卡| 成人福利视频在线看| 中文字幕av一区二区三区免费看 | 国产精品一区在线观看你懂的| 91精品国产色综合久久| 午夜亚洲国产au精品一区二区| 在线观看一区二区精品视频| 亚洲少妇中出一区| 91麻豆国产精品久久| 亚洲伦理在线精品| 在线观看免费成人| 亚洲成人自拍网| 欧美精品tushy高清| 亚洲一区在线观看视频| 欧美影院一区二区| 亚洲成人免费在线| 这里只有精品电影| 美女视频网站久久| 久久综合久久99| 国产福利91精品| 中文字幕第一区第二区| 99久久精品免费看国产免费软件| 亚洲欧洲精品一区二区三区不卡| 91一区二区三区在线观看| 亚洲精品免费播放| 欧美日韩在线精品一区二区三区激情| 亚洲三级理论片| 欧美性猛交xxxx黑人交| 亚洲va韩国va欧美va精品 | 亚洲激情一二三区| 色先锋久久av资源部| 亚洲午夜久久久久久久久久久| 欧美日韩另类国产亚洲欧美一级| 婷婷丁香久久五月婷婷| 精品成a人在线观看| 成人免费的视频| 亚洲电影一区二区三区| 精品黑人一区二区三区久久| 国产成人在线色| 亚洲精品高清视频在线观看| 7777精品久久久大香线蕉 | 欧美蜜桃一区二区三区| 日韩精品国产精品| 久久美女艺术照精彩视频福利播放| 国产成人午夜片在线观看高清观看| 国产寡妇亲子伦一区二区| 国产精品麻豆视频| 欧美日韩一区二区三区在线看| 奇米一区二区三区av| 国产午夜精品一区二区三区四区 | 国产精品久久久久久久蜜臀| 色综合天天视频在线观看| 日本麻豆一区二区三区视频| 国产视频一区不卡| 欧美在线观看视频在线| 国产毛片精品视频| 亚洲精品日产精品乱码不卡| 欧美一区二区视频在线观看2020 | 日韩—二三区免费观看av| 国产香蕉久久精品综合网| 欧美又粗又大又爽| 国产精品一区二区三区网站| 亚洲影院在线观看| 精品国产一区二区亚洲人成毛片| 99久久精品费精品国产一区二区| 日韩激情视频在线观看| 国产精品色婷婷久久58| 7777精品久久久大香线蕉| 波多野结衣的一区二区三区| 日韩在线观看一区二区| 中文文精品字幕一区二区| 91麻豆精品国产91久久久资源速度| 国产乱码字幕精品高清av| 亚洲国产中文字幕| 久久精品一区八戒影视| 欧美精品色综合| 99re这里都是精品| 国产美女娇喘av呻吟久久| 丝袜国产日韩另类美女| 亚洲人妖av一区二区| 久久综合久久久久88| 欧美日韩一级片在线观看| 成人在线视频一区二区| 久久er99精品| 天堂蜜桃一区二区三区| 尤物在线观看一区| 国产欧美日韩视频在线观看| 69精品人人人人| 91久久国产最好的精华液| 国产成a人亚洲精| 狠狠色丁香婷婷综合久久片| 亚洲成人你懂的| 伊人色综合久久天天| 国产精品九色蝌蚪自拍| 久久久一区二区三区| 日韩欧美第一区| 91精品国产91久久久久久最新毛片| 99精品视频在线观看免费| 国产电影一区二区三区| 国产一区二区三区| 经典三级在线一区| 麻豆久久久久久久| 日韩国产欧美在线视频| 亚洲午夜激情网站| 亚洲乱码一区二区三区在线观看| 中文在线一区二区| 国产精品人成在线观看免费 | 国产精品久久久久久久久免费桃花 | 99久久久精品| av一区二区三区黑人| 大胆欧美人体老妇| 成人免费毛片aaaaa**| 国产成人综合自拍|