44 lines
1.2 KiB
Java
44 lines
1.2 KiB
Java
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.util.*;
|
|
import java.awt.event.*;
|
|
|
|
public class Fond extends JPanel implements ActionListener{
|
|
|
|
public Fond(){
|
|
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);
|
|
}
|
|
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
String command = e.getActionCommand();
|
|
switch (command) {
|
|
case "Cyan":
|
|
this.setBackground(Color.CYAN);
|
|
break;
|
|
case "Magenta":
|
|
this.setBackground(Color.MAGENTA);
|
|
break;
|
|
case "Jaune":
|
|
this.setBackground(Color.YELLOW);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
}
|
|
} |