How do I call a button to perform an action in my code? I know to use action listeners, but what if the button doesn't have a variable name like below?
I'm new to Java, so please be patient with me.
public class Game
{
public static void main (String[] args)
{
JFrame frame = new JFrame ("Game");
frame.setLayout(new GridLayout(7, 6));
for(int i = 0; i < 42; i++)
{
frame.add(new JButton()); // This is the part I'm talking about!!!
}
frame.getContentPane().add(new gameBoard());
frame.pack();
frame.setVisible(true);
}
Thanks.