Tic Tac Toe in Swing This is a Tic Tac Toe game I wrote in Java (Swing). It fully works when detecting the winner or a tie. I'm wondering if there's any way I can improve it or clean it up. 

I'm trying to achieve a 3 by 3 simple Tic Tac Toe game. The first player is X and the second player is O.

My X and O buttons are images. When a button is pressed, the value goes up. If it's odd, it's X. If it's even, it's O.

Because I didn't know how to compare images, I stored a parallel String array to compare the values. Should I be using a 2-D array?

/* Tic Tac Toe */

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class TicTacToe implements ActionListener {
    JFrame window = new JFrame("Tic Tac Toe");
    JButton b[] = new JButton[9];

    String letter = "";
    ImageIcon X;
    ImageIcon O;
    ImageIcon ltr;
    int value = 0;
    boolean win = false;
    String[] letters = new String[9];

    public TicTacToe() {
        // Initialize Array
        for (int i = 0; i &lt; 9; i++) {
            letters[i] = "";
        }

        // Assign images
        X = new ImageIcon(getClass().getResource("X.png"));
        O = new ImageIcon(getClass().getResource("O.png"));
        // Create the Window
        window.setSize(500,500);
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.setLayout(new GridLayout(3,3));

        // Add Buttons
        for (int i = 0; i &lt; 9; i++) {
            b[i] = new JButton();
            window.add(b[i]);
        }

        // Add ActionListener
        for (int i = 0; i &lt; 9; i++) {
            b[i].addActionListener(this);
        }

        window.setVisible(true);
    }

    public void actionPerformed(ActionEvent a) {
        value++;
        // Who's Turn
        if (value % 2 == 1) {
            ltr = X;
            letter = "X";
        }
        if (value % 2 == 0) {
            ltr = O;
            letter = "O";
        }

        // Display Letters
        for (int i = 0; i &lt; 9; i++) {
            if (a.getSource() == b[i]) {
                b[i].setIcon(ltr);
                b[i].setDisabledIcon(ltr);
                b[i].setEnabled(false);
                letters[i] = letter;
            }
        }

        // Who Won

        // Horizontal
        if (letters[0].equals(letters[1]) &amp;&amp; letters[1].equals(letters[2]) &amp;&amp; !letters[0].equals("")) {
            win = true;
        } else if (letters[3].equals(letters[4]) &amp;&amp; letters[4].equals(letters[5]) &amp;&amp; !letters[3].equals("")) {
            win = true;
        } else if (letters[6].equals(letters[7]) &amp;&amp; letters[7].equals(letters[8]) &amp;&amp; !letters[6].equals("")) {
            win = true;
        }

        // Vertical
        if (letters[0].equals(letters[3]) &amp;&amp; letters[3].equals(letters[6]) &amp;&amp; !letters[0].equals("")) {
            win = true;
        } else if (letters[1].equals(letters[4]) &amp;&amp; letters[4].equals(letters[7]) &amp;&amp; !letters[1].equals("")) {
            win = true;
        } else if (letters[2].equals(letters[5]) &amp;&amp; letters[5].equals(letters[8]) &amp;&amp; !letters[2].equals("")) {
            win = true;
        }

        // Diagonal
        if (letters[0].equals(letters[4]) &amp;&amp; letters[4].equals(letters[8]) &amp;&amp; !letters[0].equals("")) {
            win = true;
        } else if (letters[2].equals(letters[4]) &amp;&amp; letters[4].equals(letters[6]) &amp;&amp; !letters[2].equals("")) {
            win = true;
        }

        if (win) {
            JOptionPane.showMessageDialog(null, "Player " + letter + " wins!");
            for (JButton i : b) {
                i.setEnabled(false);
            }
        } else if (!win &amp;&amp; value == 9) {
            JOptionPane.showMessageDialog(null, "The game ended in a tie.");
        }
    }

    public static void main(String[] args) {
        new TicTacToe();
    }
}
Change your fields' visibility to private as others object shouldn't know (nor care) about the inner working of your TicTacToe, this is known as Encapsulation
Turn the buttons into a 2D array and make the name clearer (b isn't really informative ^^)
Avoid magic numbers (talking about 3, 9, 500 which can be replaced by GRID_LENGTH, GRID_SIZE...) : this way, not only it's clearer for a newcomer but if you ever change one value it'll be updated everywhere
I don't think there is any point in making win a field, it's only used like a local variable
Turn the // WHO WON part into a method that'll do all the checks for you and return you a boolean : in general, calling multiple short methods makes for a clearer code as the code is more declarative this way (and it removes useless comments)
For same reasons as above, turn the victory message printing into its own method
Use a for loop to check every lines and every columns without caring for their size, that'll make for a clearer code and it'll also be easier to modify the current behaviour (if you ever want to allow for differents grid size)
You may want to not compute diagonals unless someone has checked one of the diagonal value, it'll probably slighty increase cyclomatic complexity though so it's up to you ;)
You forgot to disable the buttons if the game ends in a tie... in the same way as points 5 and 6, creating a disableTicTacToe or disableFrame method may be neat
Maybe you should consider offering the players a new game when one has ended