Modify the user interface for the tic-tac-toe program for two human players so that it uses a GUI. As before, the program maintains the data model of the game as a TTTBoard object. But now the game board should be displayed in a panel that contains a two-dimensional grid of buttons. The labels of the buttons initially are blanks. The players take turns pressing these buttons, and the program tracks whose turn it is, as before. When a player presses a blank button, its label changes to that player’s letter and the TTTBoard object is updated. Presses of non-blank buttons are ignored. When a win or tie occurs, the players are notified with a message box. You should also include a separate New Game button that resets the display to blank buttons and resets the data model for the game. (Hints: Place the board buttons in a two-dimensional array and use this array to reset the buttons when the user wants a new game. Define an action listener class that contains references to a board button and its row and column in the grid. Attach a new instance of this class to each board button. Use the methods getText and setText to observe and modify a button’s label.)
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here