0

I'm creating a GUI that will create a board with (n, n) dimensions.

I.e if the user inputs 9, it will create a board with 9 rows and 9 columns

I created a 2D array but I'm having difficulties in how to implement the user input.

I have:

    BoardButtons button[][];

How would I instantiate that in the constructor?

3
  • Which programming language are you using? Commented Mar 3, 2016 at 22:16
  • Ah,yes I should have put that, I'm using Java Commented Mar 3, 2016 at 22:17
  • BoardButtons button[][] = new BoardButtons[x][y]; Commented Mar 3, 2016 at 22:23

1 Answer 1

1

This should do the trick with the constructor

private BoardButtons[][] buttons;

public Board(int size){
    buttons = new BoardButtons[size][size];
}
Sign up to request clarification or add additional context in comments.

2 Comments

What if the parameters are two other Objects?
@CenaMaine How could they be? You said the user inputs the size of the board. Could you give an example?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.