import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * @author Remi Forax
 *
 */
public class FieldInListener {

  static class MyActionListener implements ActionListener {
    public MyActionListener(JPanel panel) {
      this.panel=panel;
    }
    public void actionPerformed(ActionEvent event) {
      panel.setBackground(Color.RED);
    }
    private final JPanel panel;
  }

  public static void main(String[] args) {
    JPanel panel=new JPanel();
        
    JButton button=new JButton("Test");
    JButton button2=new JButton("Test2");
    
    ActionListener l=new MyActionListener(panel);
    button.addActionListener(l);
    button2.addActionListener(l);
    
    panel.add(button);
    panel.add(button2);

    JFrame frame=new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(panel);
    frame.setSize(300,200);
    frame.show();
  }
}
