src/demo/TicTacToe.java
public void paintComponent(Graphics g) {
            panelLock.lock();
            if (gameBoard == null) return;
            super.paintComponent(g);
            boolean darkColor = true;
            for (int row = 0; row < boardSize; row++) {
                for (int col = 0; col < boardSize; col++) {
                    if (darkColor) g.setColor(Color.GRAY);
                    else g.setColor(Color.LIGHT_GRAY);
                    g.fillRect(row * tileSize, col * tileSize, tileSize, tileSize);
                    darkColor = !darkColor;
                    g.setColor(Color.BLACK);
                }
            }
            for (int row = 0; row < boardSize; row++) {
                for (int col = 0; col < boardSize; col++) {
                    g.setFont(new Font("ARIAL", Font.PLAIN, 32));
                    if (gameBoard != null) {
                        if (gameBoard[row][col] == GameSlotType.NOUGHT) g.drawString("O", col * tileSize + 40, row * tileSize + 60);
                        if (gameBoard[row][col] == GameSlotType.CROSS) g.drawString("X", col * tileSize + 40, row * tileSize + 60);
                    }
                }
            }
            if (currentHumanPlayerRole != null && gameStatus != GameStatus.ONGOING) {
                g.setFont(new Font("ARIAL", Font.PLAIN, 32));
                g.setColor(Color.RED);
                if (gameStatus == GameStatus.DRAW) g.drawString("DRAW", 100, 165);
                if (gameStatus == GameStatus.NOUGHT_WON) g.drawString("NOUGHT WON", 50, 165);
                if (gameStatus == GameStatus.CROSS_WON) g.drawString("CROSS WON", 50, 165);
            }
            panelLock.unlock();
        }
/**
         * Paints gameBoard to JPanel.
         *
         * @param g graphics.
         */
Paints gameBoard to JPanel.
@param g graphics.
Paints gameBoard to JPanel . @param g graphics .
public void paintComponent(Graphics g) {
            panelLock.lock();
            if (gameBoard == null) return;
            super.paintComponent(g);
            boolean darkColor = true;
            for (int row = 0; row < boardSize; row++) {
                for (int col = 0; col < boardSize; col++) {
                    if (darkColor) g.setColor(Color.GRAY);
                    else g.setColor(Color.LIGHT_GRAY);
                    g.fillRect(row * tileSize, col * tileSize, tileSize, tileSize);
                    darkColor = !darkColor;
                    g.setColor(Color.BLACK);
                }
            }
            for (int row = 0; row < boardSize; row++) {
                for (int col = 0; col < boardSize; col++) {
                    g.setFont(new Font("ARIAL", Font.PLAIN, 32));
                    if (gameBoard != null) {
                        if (gameBoard[row][col] == GameSlotType.NOUGHT) g.drawString("O", col * tileSize + 40, row * tileSize + 60);
                        if (gameBoard[row][col] == GameSlotType.CROSS) g.drawString("X", col * tileSize + 40, row * tileSize + 60);
                    }
                }
            }
            if (currentHumanPlayerRole != null && gameStatus != GameStatus.ONGOING) {
                g.setFont(new Font("ARIAL", Font.PLAIN, 32));
                g.setColor(Color.RED);
                if (gameStatus == GameStatus.DRAW) g.drawString("DRAW", 100, 165);
                if (gameStatus == GameStatus.NOUGHT_WON) g.drawString("NOUGHT WON", 50, 165);
                if (gameStatus == GameStatus.CROSS_WON) g.drawString("CROSS WON", 50, 165);
            }
            panelLock.unlock();
        }
public void paintComponent ( Graphics g ) { panelLock . lock ( ) ; if ( gameBoard == null ) return ; super . paintComponent ( g ) ; boolean darkColor = true ; for ( int row = 0 ; row < boardSize ; row ++ ) { for ( int col = 0 ; col < boardSize ; col ++ ) { if ( darkColor ) g . setColor ( Color . GRAY ) ; else g . setColor ( Color . LIGHT_GRAY ) ; g . fillRect ( row * tileSize , col * tileSize , tileSize , tileSize ) ; darkColor = ! darkColor ; g . setColor ( Color . BLACK ) ; } } for ( int row = 0 ; row < boardSize ; row ++ ) { for ( int col = 0 ; col < boardSize ; col ++ ) { g . setFont ( new Font ( "ARIAL" , Font . PLAIN , 32 ) ) ; if ( gameBoard != null ) { if ( gameBoard [ row ] [ col ] == GameSlotType . NOUGHT ) g . drawString ( "O" , col * tileSize + 40 , row * tileSize + 60 ) ; if ( gameBoard [ row ] [ col ] == GameSlotType . CROSS ) g . drawString ( "X" , col * tileSize + 40 , row * tileSize + 60 ) ; } } } if ( currentHumanPlayerRole != null && gameStatus != GameStatus . ONGOING ) { g . setFont ( new Font ( "ARIAL" , Font . PLAIN , 32 ) ) ; g . setColor ( Color . RED ) ; if ( gameStatus == GameStatus . DRAW ) g . drawString ( "DRAW" , 100 , 165 ) ; if ( gameStatus == GameStatus . NOUGHT_WON ) g . drawString ( "NOUGHT WON" , 50 , 165 ) ; if ( gameStatus == GameStatus . CROSS_WON ) g . drawString ( "CROSS WON" , 50 , 165 ) ; } panelLock . unlock ( ) ; }
Paints gameBoard to JPanel.
Paints gameBoard to JPanel .