import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

class ButtonPanel extends JPanel implements ActionListener {   
	private static final long serialVersionUID = 1L;
	private JButton redButton; 
	private JButton greenButton; 
	private JButton blueButton; 
	
	public ButtonPanel() { 
		redButton = new JButton("Rojo"); 
		greenButton = new JButton("Verde"); 
		blueButton = new JButton("Azul"); 
		 
		this.add(greenButton); 
		this.add(blueButton);
		this.add(redButton);
		
		redButton.addActionListener(this); 
		greenButton.addActionListener(this); 
		blueButton.addActionListener(this);
	} 
	
	public void actionPerformed (ActionEvent event) { 
		Object source = event.getSource(); 
		Color color = getBackground(); 
		
		if (source == redButton)  
			color = Color.RED; 
		else if (source == greenButton)  
				color = Color.GREEN; 
			 else if (source == blueButton) 
				 	color = Color.BLUE; 
		
		setBackground(color); 
		repaint();
	} 
} 