Hey Everybody

I'm just confused on something for my tic tac toe game. I have to make one in a java gui and im just confused as to how i should go abouts displaying the buttons on the board. What i'm trying to say is why is it better to use a 2d array instead of a regular for loop?
The below code does work but I just see so many other examples using a 2D array. I know it's probably a dumb question but if someone could just give me some clarification that would be great.

    for(int i =0; i <= 8; i++)
    {
        buttons[i] = new JButton();
        panel.add(buttons[i]);
        buttons[i].setActionCommand("CLICK"+i);
        buttons[i].addActionListener(new ButtonListener());
    }

use a 2d array instead of a regular for loop

Apples and oranges.
An array is used to store data
A loop controls execution

how i should go abouts displaying the buttons on the board.

How does that question relate to the posted code?
You'd use some layout manager to position and display the buttons.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.