The relevent parts of this code causing the problem are in between the ------------ dashes....
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
public class Game3 extends JFrame implements ActionListener {
private int[][] winCombinations = new int[][]{
{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, //horizontal wins
{0, 3, 6}, {1, 4, 7}, {2, 5, 8}, //virticle wins
{0, 4, 8}, {2, 4, 6} //diagonal wins
};
private JFrame gameWindow = new JFrame("TIC-TAC-TOE");
private JButton buttons[] = new JButton[9];
private JPanel biggerPanel;
private JPanel winnerPanel;
private int count = 0;
private String letter = ""; //The player X or O is initialized to empty string
private boolean win = false;
public static final int WIDTH = 400;
public static final int HEIGHT = 300;
private JLabel winnerLabel = new JLabel("");
public Game3() {
gameWindow.setSize(WIDTH, HEIGHT);
gameWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gameWindow.setLayout(new BorderLayout());
JPanel winnerPanel = new JPanel();
winnerPanel.setBackground(Color.MAGENTA);
winnerPanel.setLayout(new FlowLayout());
// -----------------------------------------------------------
win = winBool();
if (win == true) {
JLabel winnerLabel = new JLabel(letter + " WINS!");
winnerPanel.add(winnerLabel);
gameWindow.add(winnerPanel, BorderLayout.NORTH);
} else if (count == 9 && win == false) {
JLabel winnerLabel1 = new JLabel("Tie Game!");
winnerPanel.add(winnerLabel1);
gameWindow.add(winnerPanel, BorderLayout.NORTH);
}
// -----------------------------------------------------------
JPanel biggerPanel = new JPanel();
biggerPanel.setLayout(new GridLayout(3, 3));
gameWindow.add(biggerPanel, BorderLayout.CENTER);
for (int i = 0; i <= 8; i++) {
buttons[i] = new JButton();
buttons[i].setBackground(Color.WHITE);
biggerPanel.add(buttons[i]);
buttons[i].addActionListener(this);
}
gameWindow.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
count++;
if (count == 1 || count == 3 || count == 5 || count == 7 || count == 9) {
letter = "X";
} else if (count == 2 || count == 4 || count == 6 || count == 8 || count == 10) {
letter = "O";
}
JButton pressedButton = (JButton) e.getSource();
pressedButton.setText(letter);
pressedButton.setEnabled(false);
for (int i = 0; i <= 7; i++) {
if (buttons[winCombinations[i][0]].getText().equals(buttons[winCombinations[i][1]].getText())
&& buttons[winCombinations[i][1]].getText().equals(buttons[winCombinations[i][2]].getText())
&& buttons[winCombinations[i][0]].getText() != "") {
win = true;
}
}
}
// -------------------------------------------------------------------------------------
public boolean winBool() {
return win;
}
// ----------------------------------------------------------------------------------------
public static void main(String[] args) {
Game3 game3 = new Game3();
}
}