0

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());
    }

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by NormR1
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.