void AI() {

        String c1 = box1.getText();
        String c2 = box2.getText();
        String c3 = box3.getText();
        String c4 = box4.getText();
        String c5 = box5.getText();
        String c6 = box6.getText();
        String c7 = box7.getText();
        String c8 = box8.getText();
        String c9 = box9.getText();
        if ((i % 2) == 1) {
            if ((c1.equals(c2)) && (c2.equals("X")) && (b3 == 0)) {
                box3.setText("O");
                b3 = 1;
                i++;
            } else if ((c3.equals(c2)) && (c2.equals("X")) && (b1 == 0)) {
                box1.setText("O");
                b1 = 1;
                i++;
            } else if ((c1.equals(c3)) && (c1.equals("X")) && (b2 == 0)) {
                box2.setText("O");
                b2 = 1;
                i++;
            } else if ((c4.equals(c5)) && (c5.equals("X")) && (b6 == 0)) {
                box6.setText("O");
                b6 = 1;
                i++;
            } else if ((c6.equals(c5)) && (c5.equals("X")) && (b4 == 0)) {
                box4.setText("O");
                b4 = 1;
                i++;
            } else if ((c4.equals(c6)) && (c4.equals("X")) && (b5 == 0)) {
                box5.setText("O");
                b5 = 1;
                i++;
            } else if ((c7.equals(c8)) && (c8.equals("X")) && (b9 == 0)) {
                box9.setText("O");
                b9 = 1;
                i++;
            } else if ((c9.equals(c8)) && (c8.equals("X")) && (b7 == 0)) {
                box7.setText("O");
                b7 = 1;
                i++;
            } else if ((c7.equals(c9)) && (c7.equals("X")) && (b8 == 0)) {
                box8.setText("O");
                b8 = 1;
                i++;
            } else if ((c1.equals(c4)) && (c4.equals("X")) && (b7 == 0)) {
                box7.setText("O");
                b7 = 1;
                i++;
            } else if ((c7.equals(c4)) && (c4.equals("X")) && (b1 == 0)) {
                box1.setText("O");
                b1 = 1;
                i++;
            } else if ((c1.equals(c7)) && (c1.equals("X")) && (b4 == 0)) {
                box4.setText("O");
                b4 = 1;
                i++;
            } else if ((c2.equals(c5)) && (c5.equals("X")) && (b8 == 0)) {
                box8.setText("O");
                b8 = 1;
                i++;
            } else if ((c8.equals(c5)) && (c5.equals("X")) && (b2 == 0)) {
                box2.setText("O");
                b2 = 1;
                i++;
            } else if ((c2.equals(c8)) && (c2.equals("X")) && (b5 == 0)) {
                box5.setText("O");
                b5 = 1;
                i++;
            } else if ((c3.equals(c6)) && (c6.equals("X")) && (b9 == 0)) {
                box9.setText("O");
                b9 = 1;
                i++;
            } else if ((c9.equals(c6)) && (c6.equals("X")) && (b3 == 0)) {
                box3.setText("O");
                b3 = 1;
                i++;
            } else if ((c3.equals(c9)) && (c3.equals("X")) && (b6 == 0)) {
                box6.setText("O");
                b6 = 1;
                i++;
            } else if ((c1.equals(c5)) && (c5.equals("X")) && (b9 == 0)) {
                box9.setText("O");
                b9 = 1;
                i++;
            } else if ((c9.equals(c5)) && (c5.equals("X")) && (b1 == 0)) {
                box1.setText("O");
                b1 = 1;
                i++;
            } else if ((c1.equals(c9)) && (c1.equals("X")) && (b5 == 0)) {
                box5.setText("O");
                b5 = 1;
                i++;
            } else if ((c3.equals(c5)) && (c5.equals("X")) && (b7 == 0)) {
                box7.setText("O");
                b7 = 1;
                i++;
            } else if ((c7.equals(c5)) && (c5.equals("X")) && (b3 == 0)) {
                box3.setText("O");
                b3 = 1;
                i++;
            } else if ((c3.equals(c7)) && (c3.equals("X")) && (b5 == 0)) {
                box5.setText("O");
                b5 = 1;
                i++;
            } else {
                if (i == 1) {
                    if (b5 == 0) {
                        box5.setText("O");
                        b5 = 1;
                        i++;
                    } else {
                        Random a1 = new Random();
                        int first = a1.nextInt((4));
                        first++;
                        if ((first == 1) && (b1 == 0)) {
                            box1.setText("O");
                            b1 = 1;
                            i++;
                        } else if ((first == 2) && (b3 == 0)) {
                            box3.setText("O");
                            b3 = 1;
                            i++;
                        } else if ((first == 3) && (b7 == 0)) {
                            box7.setText("O");
                            b7 = 1;
                            i++;
                        } else if ((first == 4) && (b9 == 0)) {
                            box9.setText("O");
                            b9 = 1;
                            i++;
                        }
                    }
                } else if (((c1.equals(c9)) && (c9.equals("X")))
                        || ((c3.equals(c7)) && (c7.equals("X")))
                        && (i == 3)) {
                    box6.setText("O");
                    b6 = 1;
                    i++;
                } else if (i > 1) {

                    boolean done = false;
                    if (i != 9) {
                        while (done == false) {
                            Random a2 = new Random();
                            int scnd = a2.nextInt((9));
                            scnd++;

                            if ((scnd == 1) && (b1 == 0)) {
                                box1.setText("O");
                                b1 = 1;
                                i++;
                                done = true;
                            } else if ((scnd == 2) && (b2 == 0) && (b1 == 1) && (b3 == 1) && (b7 == 1) && (b9 == 1)) {
                                box2.setText("O");
                                b2 = 1;
                                i++;
                                done = true;
                            } else if ((scnd == 3) && (b3 == 0)) {
                                box3.setText("O");
                                b3 = 1;
                                i++;
                                done = true;
                            } else if ((scnd == 4) && (b4 == 0) && (b1 == 1) && (b3 == 1) && (b7 == 1) && (b9 == 1)) {
                                box4.setText("O");
                                b4 = 1;
                                i++;
                                done = true;
                            } else if ((scnd == 5) && (b3 == 0)) {
                                box3.setText("O");
                                b3 = 1;
                                i++;
                                done = true;
                            } else if ((scnd == 6) && (b6 == 0) && (b1 == 1) && (b3 == 1) && (b7 == 1) && (b9 == 1)) {
                                box6.setText("O");
                                b6 = 1;
                                i++;
                                done = true;
                            } else if ((scnd == 7) && (b7 == 0)) {
                                box7.setText("O");
                                b7 = 1;
                                i++;
                                done = true;
                            } else if ((scnd == 8) && (b8 == 0) && (b1 == 1) && (b3 == 1) && (b7 == 1) && (b9 == 1)) {
                                box8.setText("O");
                                b8 = 1;
                                i++;
                                done = true;
                            } else if ((scnd == 9) && (b9 == 0)) {
                                box9.setText("O");
                                b9 = 1;
                                i++;
                                done = true;
                            }
                        }
                    }
                }


            }

        }
    }