I'm trying to use an actionlistener in an array of buttons to change the color of the button then set the string value of the pressed button into the String called Letters. My issue is under my action performed section, the error i'm receiving is "Cannot find Symbol Symbol: getText()
this is the code for adding the actionlistener
for (int i = 0; i < buttons.length; i++) {
buttons[i] = new JButton(String.valueOf(Alphabet[i]));
buttons[i].addActionListener(new Pick());
alphabetWindow.add(buttons[i]);
}
the code for when the button is pressed.
static class Pick implements ActionListener {
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();//gets which button was pressed
((Component) source).setBackground(Color.green);
Letter = ((Component) source).getText();
}
}
Any help will be greatly appreciated.
Thank you