import javax.swing.*; import java.awt.*; import java.util.*; import java.awt.event.*; public class Fond extends JPanel implements ActionListener{ private Color coul_fond; public Fond(Color couleur){ super(); // Création des boutons JButton cyanButton = new JButton("Cyan"); JButton magentaButton = new JButton("Magenta"); JButton yellowButton = new JButton("Jaune"); // Ajout des action listeners aux boutons cyanButton.addActionListener(this); magentaButton.addActionListener(this); yellowButton.addActionListener(this); // Création du panneau pour contrôler la couleur de fond this.add(cyanButton); this.add(magentaButton); this.add(yellowButton); this.setBackground(couleur); coul_fond = couleur; } public Color Der_col(){ return coul_fond; } @Override public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); switch (command) { case "Cyan": this.setBackground(Color.CYAN); coul_fond = Color.CYAN; break; case "Magenta": this.setBackground(Color.MAGENTA); coul_fond = Color.MAGENTA; break; case "Jaune": this.setBackground(Color.YELLOW); coul_fond = Color.YELLOW; break; default: break; } } }