I have to make a program that inputs the user's count of columns and rows to use in the chess board. When the board is created it has to be full of buttons fitting the amount of columns and rows specified by the user. I figured I'd have to make the buttons an array from the input because it is impossible to figure out how many buttons nor am i going to hard code 60+ new buttons. This is what I have so far.. It prompts the user to import the number of columns and rows and sets them to the int numRows,numCols. Where I am confused is the button array, we have not covered it in class and was just wondering how to set up the array with the buttons. The rest of the program is using ActionListener and actionPerformed so when the user clicks the button it will say "Button 1 clicked" etc, any help would be appreciated thanks!
import javax.swing.*; import java.awt.event.*; import java.awt.GridLayout; public class ButtonBoard { public static void main(String[] args){ String rows = JOptionPane.showInputDialog("Enter number of rows"); String columns = JOptionPane.showInputDialog("Enter number of columns"); int numRows = Integer.parseInt(rows); int numCol = Integer.parseInt(columns); JFrame frame = new JFrame(); JButton button1 = new JButton("Button1"); JButton button2 = new JButton("Button2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout((new GridLayout(numRows,numCol))); frame.add(button1); frame.add(button2); frame.setSize(300,300); frame.setVisible(true); } }