title: How would I properly implement a JScrollPane GUI into my Java game?
body: <p>I've been trying for a few days to implement this "basic" GUI into my game of Tic-Tac-Toe. The outline of this code requires me to set up a basic JFrame containing a JTextArea, inside a JScrollPane GUI. All of this is in class TicTacToeFrame, which extends class TicTacToe (holds all the methods/constructor for the board, including a method that prints the board to the console). TicTacToeFrame needs to override the print() method, so the board, which is a string, will be printed to the GUI instead of the console. 
  <strong>Note</strong>, I'm required to keep:</p>
  
  <pre><code>public class TicTacToeFrame extends TicTacToe
  </code></pre>
  
  <p>They don't allow us extend from JFrame like:</p>
  
  <pre><code>public class TicTacToeFrame extends JFrame
  </code></pre>
  
  <p>What I have is shown below:</p>
  
  <p><strong>TicTacToe class (Works)</strong></p>
  
  <pre><code>import java.util.*;
  
  /**
   * A class modelling a tic-tac-toe (noughts and crosses, Xs and Os) game.
   * 
   * @author Supasta
   * @version November 20, 2019
   */
  
  public class TicTacToe
  {
     public static final String PLAYER_X = "X"; // player using "X"
     public static final String PLAYER_O = "O"; // player using "O"
     public static final String EMPTY = " ";  // empty cell
     public static final String TIE = "T"; // game ended in a tie
  
     private String player;   // current player (PLAYER_X or PLAYER_O)
  
     private String winner;   // winner: PLAYER_X, PLAYER_O, TIE, EMPTY = in progress
  
     private int numFreeSquares; // number of squares still free
  
     private String board[][]; // 3x3 array representing the board
  
     private TicTacToeFrame gui;
     /** 
      * Constructs a new Tic-Tac-Toe board.
      */
     public TicTacToe()
     {
        board = new String[3][3];
     }
  
     /**
      * Sets everything up for a new game.  Marks all squares in the Tic Tac Toe board as empty,
      * and indicates no winner yet, 9 free squares and the current player is player X.
      */
     private void clearBoard()
     {
        for (int i = 0; i &lt; 3; i++) {
           for (int j = 0; j &lt; 3; j++) {
              board[i][j] = EMPTY;
           }
        }
        winner = EMPTY;
        numFreeSquares = 9;
        player = PLAYER_X;     // Player X always has the first turn.
     }
  
  
     /**
      * Plays one game of Tic Tac Toe.
      */
  
     public void playGame()
     {
        int row, col;
        Scanner sc;
  
        clearBoard(); // clear the board
  
        gui = new TicTacToeFrame();
  
        // print starting board
        gui.print();
  
        // loop until the game ends
        while (winner==EMPTY) { // game still in progress
  
           // get input (row and column)
           while (true) { // repeat until valid input
              System.out.print("Enter row and column of chosen square (0, 1, 2 for each): ");
              sc = new Scanner(System.in);
              row = sc.nextInt();
              col = sc.nextInt();
              if (row&gt;=0 &amp;&amp; row&lt;=2 &amp;&amp; col&gt;=0 &amp;&amp; col&lt;=2 &amp;&amp; board[row][col]==EMPTY) break;
              System.out.println("Invalid selection, try again.");
           }
  
           board[row][col] = player;        // fill in the square with player
           numFreeSquares--;            // decrement number of free squares
  
           // see if the game is over
           if (haveWinner(row,col)) 
              winner = player; // must be the player who just went
           else if (numFreeSquares==0) 
              winner = TIE; // board is full so it's a tie
  
           // print current board
           print();
  
           // change to other player (this won't do anything if game has ended)
           if (player==PLAYER_X) 
              player=PLAYER_O;
           else 
              player=PLAYER_X;
        }
  
     } 
  
  
     /**
      * Returns true if filling the given square gives us a winner, and false
      * otherwise.
      *
      * @param int row of square just set
      * @param int col of square just set
      * 
      * @return true if we have a winner, false otherwise
      */
     private boolean haveWinner(int row, int col) 
     {
         // unless at least 5 squares have been filled, we don't need to go any further
         // (the earliest we can have a winner is after player X's 3rd move).
  
         if (numFreeSquares&gt;4) return false;
  
         // Note: We don't need to check all rows, columns, and diagonals, only those
         // that contain the latest filled square.  We know that we have a winner 
         // if all 3 squares are the same, as they can't all be blank (as the latest
         // filled square is one of them).
  
         // check row "row"
         if ( board[row][0].equals(board[row][1]) &amp;&amp;
              board[row][0].equals(board[row][2]) ) return true;
  
         // check column "col"
         if ( board[0][col].equals(board[1][col]) &amp;&amp;
              board[0][col].equals(board[2][col]) ) return true;
  
         // if row=col check one diagonal
         if (row==col)
            if ( board[0][0].equals(board[1][1]) &amp;&amp;
                 board[0][0].equals(board[2][2]) ) return true;
  
         // if row=2-col check other diagonal
         if (row==2-col)
            if ( board[0][2].equals(board[1][1]) &amp;&amp;
                 board[0][2].equals(board[2][0]) ) return true;
  
         // no winner yet
         return false;
     }
  
  
     /**
      * Prints the board to standard out using toString().
      */
      public void print() 
      {
          System.out.println(toString());
      }
  
  
     /**
      * Returns a string representing the current state of the game.  This should look like
      * a regular tic tac toe board, and be followed by a message if the game is over that says
      * who won (or indicates a tie).
      *
      * @return String representing the tic tac toe game state
      */
      public String toString() 
      {
          String currentState = "";
          String progress = "";
  
          for(int i=0 ; i &lt; 3; ++i){
              currentState += board[i][0] + " | " + board[i][1] + " | " + board[i][2] + "\n";
  
              if(i == 2){
                  break;
              }
  
              currentState += "------------\n";
          }
  
          /* Prints the winner, only if there is a winner */
          if(winner != EMPTY){
              if(this.winner == TIE){
                  progress = ("The games ends in a tie!");
              }
              else{
                  progress = ("Game over, " + player + " wins!");
              }
          }
          else{
              progress = "Game in progress";
          }
          return currentState + "\n" + progress + "\n";
      }
  
  }
  </code></pre>
  
  <p><strong>TicTacToeFrame class (broken)</strong></p>
  
  <pre><code>import java.util.*;
  import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  
  /**
   * A class modelling a tic-tac-toe (noughts and crosses, Xs and Os) game in a very
   * simple GUI window.
   * 
   * @author Supasta
   * @version November 20, 2019
   */
  
  public class TicTacToeFrame extends TicTacToe 
  { 
     private JTextArea status; // text area to print game status
     private JFrame frame;
     private JScrollPane sta;
  
     /** 
      * Constructs a new Tic-Tac-Toe board and sets up the basic
      * JFrame containing a JTextArea in a JScrollPane GUI.
      */
     public TicTacToeFrame()
     { 
         super();
         final JFrame frame = new JFrame("Tic Tac Toe");
  
         frame.setSize(500,500);
  
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
         status = new JTextArea(super.toString());
         JScrollPane sta = new JScrollPane();
  
         sta.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);  
         sta.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  
         frame.getContentPane().add(sta);
         frame.setVisible(true);
     }
  
     /**
      * Prints the board to the GUI using toString().
      */
      public void print() 
      {  
          status.replaceSelection(toString());
      }
  
  }
  </code></pre>
  
  <p>What should I change in my TicTacToeFrame? Right now the GUI won't even appear.. And during testing, if I got it to appear, it wouldn't print any text.</p>