import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Fond extends JPanel implements ActionListener { public Fond(){ super(); JButton bouton = new JButton("Blue"); this.add(bouton); JButton bouton2 = new JButton("Red"); this.add(bouton2); JButton bouton3 = new JButton("Green"); this.add(bouton3); bouton.addActionListener(this); bouton2.addActionListener(this); bouton3.addActionListener(this); } public void actionPerformed(ActionEvent e) { if (e.getActionCommand()=="Blue") { this.setBackground(Color.BLUE); } if (e.getActionCommand()=="Red") { this.setBackground(Color.RED); } if (e.getActionCommand()=="Green") { this.setBackground(Color.GREEN); } } }