// APS101, Winter 2009: Lecture 30 (Mar. 24) // // Review: last time we wrote a GUI for our Tic-Tac-Toe game. TicTacToe t = new TicTacToe(); TTTWindow w = new TTTWindow(t); t.setMark('X', 1,1) w.update(1,1) // in order to play the game, you would need to keep doing this. // so, instead of doing this manually, we write a "main" method: public static void main(String[] args) // This is the starting point of the program. // After compiling, to run the program you can type in: java ProgramName // where ProgramName is a .class file containing the main method. // also, you can pass arguments to the main method: java ProgramName arg1 arg2 ... // then, in the main method, args[0] is arg1, args[1] is arg2 and so on. // (see TTTDriver.java that we wrote in class) java TTTDriver // this is all you need to do to run the game! // as an exercise, make the driver more robust (error-resistant): 1. if the user enters non-numbers or out of range row/column, ask again until row and column are valid. 2. if the row/column is valid but already occupied, tell the user to choose an empty cell, and keep asking for a valid cell. The best way to do this is to change the setMark() method to return true/false (false if the cell is not BLANK), so in the driver if you setMark and it is false you know the cell was not BLANK. 3. re-write the GUI so that the grid is composed of JButtons, rather than JLabels. Make these buttons clickable, so that the user does not need to enter a row and a column to make a mark on the grid.