import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;


/** A tic tac toe window */
public class TTTWindow extends JFrame {
  private TicTacToe board;
  
  /** The JLabels representing the board contents */
  private JLabel[][] squares;
  
  /** Construct a Tic Tac Toe JFrame with labels
   *  and initialize the labels to the TicTacToe ttt
   *  values 
   */
  // I added this - it makes the squares more viewable ..
  // have a look at the java tutorial for swing: 
  // http://java.sun.com/docs/books/tutorial/uiswing/misc/border.html#eg
  // there are other good hints and instructions in the swing tutorial:
  // http://java.sun.com/docs/books/tutorial/uiswing/
  Border raisedbevel = BorderFactory.createRaisedBevelBorder(); 


  public TTTWindow(TicTacToe ttt) {
    this.board = ttt;
    Container c = this.getContentPane();
    c.setLayout
      (new GridLayout
         (board.BOARD_SIZE, board.BOARD_SIZE));
    squares = new JLabel[board.BOARD_SIZE][board.BOARD_SIZE];
    
    for (int i = 0; i < board.BOARD_SIZE; i++) {
      for (int j = 0; j < board.BOARD_SIZE; j++) {
        squares[i][j] = 
          new JLabel(board.getMark(i,j )+ "", JLabel.CENTER);
        squares[i][j].setSize(100,100);
        squares[i][j].setBorder(raisedbevel); // added border here
        c.add(squares[i][j]);
      }
    }
    this.setLocation(150, 150); // move it away from the corner of the screen.
    this.setSize(300, 300); // make the board a bit bigger.
    //this.pack(); //I removed the pack command as it constrained the board to such a tiny size.
    this.show();
  }
  /**
   * Update the JFrame with most recent board values.
   */ 
  public void update() {
    for (int i = 0; i < board.BOARD_SIZE; i++) {
      for (int j = 0; j < board.BOARD_SIZE; j++) {
        squares[i][j].setText
          (String.valueOf(board.getMark(i,j)));
      }
    }
  }
}


