// APS101, Winter 2009: Lecture 29 (Mar. 23) // // Review: last time we kept developing our Tic-Tac-Toe game. // we wrote methods rowWinner(), colWinner(), and diagWinner() // now, let's put all of these into one method: getWinner() TicTacToe t = new TicTacToe(); t t.getWinner() // returns ' ' t.setMark('X', 0, 0) t.setMark('X', 1, 0) t.setMark('X', 2, 0) // this produces a column winner 'X'! t t.getWinner() // returns 'X' // but there is another possible outcome of a tic-tac-toe game... // a draw! so let's write method isDraw(), and test it. TicTacToe t = new TicTacToe(); t t.isDraw() // returns false... why? // (we simulated playing a game where no one won, and all the squares on the grid were taken up.) t.isDraw() // returns true now. // we also wrote method getMark(int r, int c). // (it will be useful for the next part of the process) // what's wrong with the game as it is now? Not very user-friendly! // we need to write a Graphical User Interface (GUI) for our game. // (see TTTWindow.java) // - we use JLabels to display the squares containing X's and O's // - we put all the graphical elements into the JFrame's content pane // JFrame // getContentPane() // pack() // Container (in the awt package) // setLayout(new GridLayout(M,N)) // JLabel // setBorder(new LineBorder(Color.BLACK)); // setHorizontalAlignment(SwingConstants.CENTER); // setVerticalAlignment(SwingConstants.CENTER); // setText(String); TicTacToe t = new TicTacToe(); t TTTWindow w = new TTTWindow(t); // empty grid t.setMark('X', 1, 1); // nothing changed in the GUI... w.update(1, 1); // now it displays the new 'X'