Code example for Formatter

Methods: flush, format

0
   } // end Player constructor 
 
   // send message that other player moved 
   public void otherPlayerMoved( int location )
   { 
      output.format( "Opponent moved\n" );
      output.format( "%d\n", location ); // send location of move
      output.flush(); // flush output
   } // end method otherPlayerMoved 
 
   // control thread's execution 
   public void run() 
   { 
      // send client its mark (X or O), process messages from client 
      try  
      { 
         displayMessage( "Player " + mark + " connected\n" );
         output.format( "%s\n", mark ); // send player's mark
         output.flush(); // flush output
 
         // if player X, wait for another player to arrive