private JButton[] buttons;
private static final Character firstChar = 'A';
private static final Character lastChar = 'D';
/** Creates a new instance of ButtonPanel */
public ButtonPanel()
{
buttons = new JButton[4];
setLayout(new GridLayout(2,2));
Character label = firstChar;
for (JButton b: buttons)
{
b = new JButton("" + label);
buttons[label - firstChar]= b;
b.setActionCommand("" + label); // for use in ButtonWatcher
label++;
add(b);
//is this how to create and add a ButtonWatcher for each of the buttons
b.addActionListener(new ButtonWatcher());
}
Ive tried this code with a buttonWatcher implements ActionListener class but it wont work and im wondering have i added the actionListener to each button correctly or is there something else i have to do?