The following code that i used adds 100 buttons onto the JPanel. But because there are so many buttons, it would not bode for me to manually make a variable name to all of them. So i'm wondering what I should do to be able to add actionlistener to all of the buttons. Since the way that i did it doesn't permit me to use "JButton.addActionListener(new MyAction(button))", since i have not set a variable to any of the variables(button).
int numButton=100;
...
JPanel pane = new JPanel(new GridLayout(10, 10));
while(numButton>0){
b_array[numButton]=pane.add(new JButton(" "+numButton));
label.setLabelFor(button);
numButton--;
}
pane.add(label);
pane.setBorder(BorderFactory.createEmptyBorder(
30, //top
30, //left
30, //bottom
30) //right
);
return pane;
}
I haven't done Java in a while, so i'm sorry if i'm doing something obvious wrong.
Thanks for replies in advance!
int numButton=100;
...
JPanel pane = new JPanel(new GridLayout(10, 10));
while(numButton>0){
b_array[numButton]=pane.add(new JButton(" "+numButton));
label.setLabelFor(button);
numButton--;
}
pane.add(label);
pane.setBorder(BorderFactory.createEmptyBorder(
30, //top
30, //left
30, //bottom
30) //right
);
return pane;
}
I haven't done Java in a while, so i'm sorry if i'm doing something obvious wrong.
Thanks for replies in advance!