title: Why is self-referencing pointer or this out of scope in button?
body: <p>I'm trying to produce a dynamic canvas using the Swing library with the State pattern. My code can compile but with red marks all over the console when my buttons are pressed. </p>
  
  <p>The problem: my self-referencing pointer or reserved word <em>this</em> is out of scope in button. I want to be able to access the class without any static.</p>
  
  <p><strong>Error: Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem: 
      The method handlePush(SP) in the type State is not applicable for the arguments (new ActionListener(){})</strong></p>
  
  <p>This is is the canvas class.     </p>
  
  <pre><code>public class SP extends JPanel{
  private static final long serialVersionUID = 1L;
  
  private State state = null; 
  
  public static void main(String[] args){
      SwingUtilities.invokeLater(new Runnable(){
          public void run(){
              createAndShowCanvasGUI();
          }
      });
  }
  public SP(State state ){
      this.state = state;
      init();
  }
  public SP(){
      this(new BlackState());
  }
  public static void createAndShowCanvasGUI(){
      JFrame frm = new JFrame("State Pattern");
      frm.setVisible(true);
      frm.setSize(400, 400);
      frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frm.setContentPane(new SP());
  }
  public void paintComponent(Graphics g){
      super.paintComponent(g);
  
      g.setColor(state.getColor());
      g.fillRect(0, 0, getWidth(), getHeight());
      repaint();
  }
  public void init(){
      JButton push = new JButton("Push");
      JButton pull = new JButton("Pull");
  
      push.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent ae){
              if(ae.getActionCommand().equals("Push")){
                  state.handlePush(this);
              }
          }
      });
      pull.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent ae){
              if(ae.getActionCommand().equals("Pull")){
                  state.handlePull(this);
              }
          }
      });
  
      add(push);
      add(pull);
  }
  public State setState(State newState){
      State oldState = state; 
      state = newState;
      return oldState;
  }
  public State getState(){
      return state; 
      }
  }
  </code></pre>
  
  <p>This is the logical state design </p>
  
  <pre><code>public abstract class State {
  
  public abstract void handlePull(SP p);
  public abstract void handlePush(SP p);
  public abstract Color getColor(); 
  }
  </code></pre>
  
  <p>Here is one variation of the State</p>
  
  <pre><code>public class GreenState extends State{
  @Override
  public void handlePull(SP c) {
      c.setState(new BlackState());
  }
  @Override
  public void handlePush(SP c) {
      // TODO Auto-generated method stub
      c.setState(new RedState());
  }
  @Override
  public Color getColor() {
      return Color.GREEN;
      }
  }
  </code></pre>