Jvelha

Disponível somente no TrabalhosFeitos
  • Páginas : 3 (503 palavras )
  • Download(s) : 0
  • Publicado : 28 de novembro de 2012
Ler documento completo
Amostra do texto
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
importjava.net.Socket;
import java.net.InetAddress;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
importjavax.swing.JTextField;
import javax.swing.SwingUtilities;
import java.util.Formatter;
import java.util.Scanner;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;public class TicTacToeClient extends JFrame implements Runnable {

private JTextField idField;
private JTextArea displayArea;
private JPanel boardPanel;
private JPanel panel2;
privateSquare[][] board;
private Square currentSquare;
private Socket connection;
private Scanner input;
private Formatter output;
private String ticTacToeHost;
private String myMark;
privateboolean myTurn;
private final String X_MARK = "X";
private final String O_MARK = "O";

public TicTacToeClient(String host) {
ticTacToeHost = host;
displayArea = new JTextArea(4, 30);displayArea.setEditable(false);
add(new JScrollPane(displayArea));

boardPanel = new JPanel();
boardPanel.setLayout(new GridLayout(3, 3, 0, 0));

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

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

}}

idField = new JTextField();
idField.setEditable(false);
add(idField, BorderLayout.NORTH);

panel2 = new JPanel();
panel2.add(boardPanel, BorderLayout.CENTER);
add(panel2,BorderLayout.CENTER);

setSize(300, 255);
setVisible(true);

startClient();

}

public void startClient() {
try {

connection = new Socket(InetAddress.getByName(ticTacToeHost), 12345);...
tracking img