title: Java: where should I put anonymous listener logic code?
body: <p>we had a debate at work about what is the best practice for using listeners in java: whether listener logic should stay in the anonymous class, or it should be in a separate method, for example:</p>
  
  <pre><code>button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
          // code here
      }
  });
  </code></pre>
  
  <p>or</p>
  
  <pre><code>button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
          buttonPressed();
      }
  });
  
  private void buttonPressed() {
      // code here
  }
  </code></pre>
  
  <p>which is the recommended way in terms of readability and maintainability? I prefer to keep the code inside the listener and only if gets too large, make it an inner class. Here I assume that the code is not duplicated anywhere else.</p>
  
  <p>Thank you. </p>