DEV/DEV2.1/TP7:Evenements/Fond.java

36 lines
892 B
Java
Raw Permalink Normal View History

2023-04-14 11:29:17 +02:00
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Fond extends JPanel implements ActionListener{
public Fond() {
super();
JButton magenta = new JButton("magenta");
JButton cyan = new JButton("cyan");
JButton jaune = new JButton("jaune");
this.add(magenta);
this.add(cyan);
this.add(jaune);
magenta.addActionListener(this);
cyan.addActionListener(this);
jaune.addActionListener(this);
}
public void actionPerformed(ActionEvent evenement){
String commande = new String();
commande="cyan";
if(true==commande.equals(evenement.getActionCommand())){
this.setBackground(Color.CYAN);
}
commande="magenta";
if(true==commande.equals(evenement.getActionCommand())){
this.setBackground(Color.MAGENTA);
}
commande="jaune";
if(true==commande.equals(evenement.getActionCommand())){
this.setBackground(Color.YELLOW);
}
}
}