I am a new to java programming and I am developing a simple a one player TICTACTOE game using swing. Thee are two classes. One main TICTACTOE class which uses an XOButtton class to set up buttons which can listen to click events. I begin by creating an object of this tictactoe class then use this object to call a method called initialCheckButton to find out if the buttons have been clicked 3 timess. If yes it calls another method to find out if the Xs or Os are consecutively displayed.If yes you win. I plan to develop this further but this is just a template. When the GUI dsiplays,clicking on buttons and display of successive Xs or Os does not display the message of the JoptionPane. Any help?
public class TicTacToe extends JFrame {
    JPanel p = new JPanel();
    boolean done = false;
    XOButton buttons[] = new XOButton[9];
    public static void main(String args[]) {
        TicTacToe t = new TicTacToe();
        t.initialCheckButton();
    }
    public TicTacToe() {
        super("TicTacToe");
        setSize(400, 400);
        setResizable(false);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        p.setLayout(new GridLayout(3, 3));
        for (int i = 0; i < 9; i++) {
            buttons[i] = new XOButton();
            p.add(buttons[i]);
        }
        add(p);
        setVisible(true);
    }
    public void initialCheckButton() {
        int sum = 0;
        while (sum <= 3) {
            for (int i = 0; i < 9; i++) {
                if (buttons[i].checkButtonO() == 1) {
                    sum++;
                }
                if (buttons[i].checkButtonX() == 1) {
                    sum++;
                }
            }
        }
        checkButtonFinal();
    }
    public void checkButtonFinal() {
        for (int i = 0; i < 9; i++)
            for (int j = i + 3; j < 9; j++) {
                for (int k = j + 3; k < 9; k++) {
                    if (buttons[i].checkButtonO() == buttons[j].checkButtonO() && buttons[k].checkButtonO() == 1)
                        JOptionPane.showMessageDialog(null, "Great, you won");
                    if (buttons[i].checkButtonX() == buttons[j].checkButtonX() && buttons[k].checkButtonX() == 1)
                        JOptionPane.showMessageDialog(null, "Great, you won");
                }
            }
        for (int i = 0; i < 9; i += 3) {
            if (buttons[i].checkButtonO() == buttons[i + 1].checkButtonO() && buttons[i + 2].checkButtonO() == 1)
                JOptionPane.showMessageDialog(null, "Great, you won");
            if (buttons[i].checkButtonX() == buttons[i + 1].checkButtonX() && buttons[i + 2].checkButtonX() == 1)
                JOptionPane.showMessageDialog(null, "Great, you won");
        }
        for (int i = 0; i < 9; i += 2) {
            for (int j = i + 2; j < 9; j += 2)
                for (int k = j + 2; k < 9; k += 2) {
                    if (buttons[i].checkButtonO() == buttons[j].checkButtonO() && buttons[k].checkButtonO() == 1)
                        JOptionPane.showMessageDialog(null, "Great, you won");
                    if (buttons[i].checkButtonX() == buttons[j].checkButtonX() && buttons[k].checkButtonX() == 1)
                        JOptionPane.showMessageDialog(null, "Great, you won");
                }
        }
        for (int i = 0; i < 9; i += 4) {
            for (int j = i + 4; j < 9; j += 4)
                for (int k = j + 4; k < 9; k += 4) {
                    if (buttons[i].checkButtonO() == buttons[j].checkButtonO() && buttons[k].checkButtonO() == 1)
                        JOptionPane.showMessageDialog(null, "Great, you won");
                    if (buttons[i].checkButtonX() == buttons[j].checkButtonX() && buttons[k].checkButtonX() == 1)
                        JOptionPane.showMessageDialog(null, "Great, you won");
                }
        }
    }
    public static class XOButton extends JButton implements ActionListener {
        public int buttonClicked = 0;
        public int buttonClickedX = 0;
        public int buttonClickedO = 0;
        ImageIcon X, O;
        byte value = 0;
        /*
         * 0:nothing 1:X 2:O
         */
        public XOButton() {
            X = new ImageIcon(this.getClass().getResource("X.png"));
            O = new ImageIcon(this.getClass().getResource("O.png"));
            this.addActionListener(this);
        }
        public void actionPerformed(ActionEvent e) {
            value++;
            value %= 3;
            switch (value) {
            case 0:
                setIcon(null);
                buttonClicked = 0;
                break;
            case 1:
                setIcon(X);
                buttonClickedX = 1;
                break;
            case 2:
                setIcon(O);
                buttonClickedO = 1;
                break;
            }
        }
        public int checkButtonO() {
            return buttonClickedO;
        }
        public int checkButtonX() {
            return buttonClickedX;
        }
    }
}
 
    
