private void reset() { button1Desc = null; button2Desc = null; button3Desc = null; button4Desc = null; button5Desc = null; button6Desc = null; button7Desc = null; button8Desc = null; button9Desc = null; button1.setIcon(null); button2.setIcon(null); button3.setIcon(null); button4.setIcon(null); button5.setIcon(null); button6.setIcon(null); button7.setIcon(null); button8.setIcon(null); button9.setIcon(null); countMove = 0; }
// constructor public TicTacToe() { super("tic-tac-toe"); JPanel all = new JPanel(new BorderLayout()); JPanel main = new JPanel(new GridLayout(3, 3)); JPanel top = new JPanel(); JPanel bottom = new JPanel(); // make choice 1 player as default choice1 = new JRadioButton("1P", true); top.add(choice1); choice2 = new JRadioButton("2P", false); top.add(choice2); // grouping radio button choiceGroup = new ButtonGroup(); choiceGroup.add(choice1); choiceGroup.add(choice2); // create handler for choice radio button ChoiceRBHandler choiceHandler = new ChoiceRBHandler(); choice1.addItemListener(choiceHandler); choice2.addItemListener(choiceHandler); // reset handler for reset button ResetButtonHandler resetHandler = new ResetButtonHandler(); resetButton.addActionListener(resetHandler); top.add(resetButton); // create handler for main button MainButtonHandler mainHandler = new MainButtonHandler(); button1.addActionListener(mainHandler); main.add(button1); button2.addActionListener(mainHandler); main.add(button2); button3.addActionListener(mainHandler); main.add(button3); button4.addActionListener(mainHandler); main.add(button4); button5.addActionListener(mainHandler); main.add(button5); button6.addActionListener(mainHandler); main.add(button6); button7.addActionListener(mainHandler); main.add(button7); button8.addActionListener(mainHandler); main.add(button8); button9.addActionListener(mainHandler); main.add(button9); // create initial and add navigate text fontPlay = new Font("Serif", Font.PLAIN, 20); fontDone = new Font("Serif", Font.BOLD, 20); navigateText = new JLabel(" YOU VS AI "); navigateText.setFont(fontPlay); bottom.add(navigateText); all.add(top, BorderLayout.NORTH); all.add(main, BorderLayout.CENTER); all.add(bottom, BorderLayout.SOUTH); getContentPane().add(all); pack(); }