I am trying to create a simple action listener. I am getting an error that says:
my code:Code:GUI.buttonHandler is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener
If you could please explain what I am doing wrong, because I have done research, and I can't understand. It has to do with the subclass, or something of the sort?Code:public class GUI extends JFrame {
private static final int WIDTH = 400;
private static final int HEIGHT = 300;
private JLabel name;
private JTextField textField;
private JButton submit;
private buttonHandler btnHandler;
public static void main(String[] args) {
GUI gui = new GUI();
}
public GUI() {
setTitle("A sameple");
setSize(WIDTH, HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
name = new JLabel("Name: ", SwingConstants.LEFT);
textField = new JTextField(10);
submit = new JButton("Submit");
btnHandler = new buttonHandler();
submit.addActionListener(btnHandler);
setTitle("Sample Title");
Container pane = getContentPane();
pane.setLayout(new GridLayout(4, 2));
pane.add(name);
pane.add(textField);
pane.add(submit);
setSize(WIDTH, HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private class buttonHandler implements ActionListener // it does not like buttonHandler here
{
public void actionPeformed(ActionEvent e)
{
textField.setText("Good!!!!(:");
}
}
