/** * This program plays a game of Tic-Tac-Toe between two human players * * @author Thomas Waltz * CS1121 * Fall 2005 * November 7, 2005 * Recitation Section 1 * Lab Section 2 */ import java.awt.*; import javax.swing.*; import java.awt.event.*; /** * This class draws the buttons and JLabels and lays them out on the screen. */ /** * There are some tags commented out. * Uncommenting them will show a JLabel of the x and y coordinates of the click. * The value of the variable "score" will also be shown in the grid. */ public class TicTacToe extends JApplet { //create variables and JLabels, JButtons, etc. private JLabel nextplayer = new JLabel("Player 1 (X)"); private JButton reset = new JButton("Reset"); private JLabel status = new JLabel("Game hasn't ended yet!"); private int score; private Game gameclass = new Game(nextplayer, status, reset); private int tttx; private int ttty; /** * This method sets up the GUI. */ public void init() { //Set the screen layout Container window = getContentPane(); window.setLayout(new FlowLayout(FlowLayout.CENTER)); //Set the size of the JPanel gameclass.setPreferredSize(new Dimension(300,300)); gameclass.setBackground(Color.white); //Add objects to the applet window.add(gameclass); window.add(nextplayer); window.add(reset); window.add(status); JLabel testvalues = new JLabel("Test"); //adds a listener in the Game class reset.addActionListener(gameclass); MListener ml = new MListener(testvalues, nextplayer, tttx, ttty, gameclass); gameclass.addMouseListener(ml); //window.add(testvalues); This will show the x & y coordinates } }