0

I have an inner listener class in my program. The compiler signals an error at the first line below and says '{' expected. I can't figure out what's wrong. I revised all my brackets and there's no problem. Here's my inner class:

private class Listener implements Action Listener
{
    public void ActionPerformed(ActionEvent e)
    {
        if(i==1 && field.equalsIgnoreCase("red"))
        {
            i++;
            label.setText("Enter color number" + i);
            field.setText("");
            return;
        }
        if(i==2 && field.equalsIgnoreCase("white"))
        {
            i++;
            label.setText("Enter color number" + i);
            field.setText("");
            return;
        }
        if(i==3 && field.equalsIgnoreCase("yellow"))
        {
            i++;
            label.setText("Enter color number" + i);
            field.setText("");
            return;
        }
        if(i==4 && field.equalsIgnoreCase("green"))
        {
            i++;
            label.setText("Enter color number" + i);
            field.setText("");
            return;
        }
        if(i==5 && field.equalsIgnoreCase("blue"))
        {
            field.setVisible(false);
            label.setText("Congratulations - your memory is perfect");
            return;
        }

        field.setVisible(false);
        label.setText("Sorry - wrong color. Eat more antioxidants");
    }
}
animuson
  • 53,861
  • 28
  • 137
  • 147
Andrew S.
  • 80
  • 1
  • 10

2 Answers2

4
Action Listener

is one word

ActionListener
MeBigFatGuy
  • 28,272
  • 7
  • 61
  • 66
  • Thanks! (and thanks to the post above) Now I have another error: "AndrewSidhomProg7.Listener is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener private class Listener implements ActionListener" – Andrew S. Oct 03 '11 at 05:01
  • Never mind. Solved it. I had ActionPerformed instead of actionPerformed. Really tired tonight and trying to get my assignment done in time. – Andrew S. Oct 03 '11 at 05:10
3

It should be implements ActionListener without the space between Action and Listener.

Paul Bellora
  • 54,340
  • 18
  • 130
  • 181