Jvelha
public class TicTacToeClient extends JFrame implements Runnable {
private JTextField idField; private JTextArea displayArea; private JPanel boardPanel; private JPanel panel2; private Square[][] board; private Square currentSquare; private Socket connection; private Scanner input; private Formatter output; private String ticTacToeHost; private String myMark; private boolean 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);