title: Why doesn't the code operate accordingly?
body: <p>I'm trying to write this code in such way that each click on the button changes the color of the panel.  I want it to cycle from red>green>blue>gray>red>... and so on.
  this is how my listener class looks like</p>
  
  <pre><code>private class Listener implements ActionListener
  {
    public void actionPerformed(ActionEvent action)
    {
       if(getBackground() == Color.RED)
          setBackground(Color.GREEN);
       else if(getBackground() == Color.GREEN)
          setBackground(Color.BLUE);
       else if(getBackground() == Color.BLUE)
          setBackground(Color.GRAY);
       else
          setBackground(Color.RED);
  
       setBackground(Color.RED);
    }
  }
  </code></pre>