Developpement/23DEV1.1/TPS2/TP01/Evènements/Fond.java

38 lines
811 B
Java
Raw Permalink Normal View History

2024-12-09 11:53:11 +01:00
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Fond extends JPanel implements ActionListener
{
public Fond()
{
super();
JButton cyan = new JButton("Cyan");
JButton magenta = new JButton("Magenta");
JButton jaune = new JButton("Jaune");
this.add(cyan);
this.add(magenta);
this.add(jaune);
cyan.addActionListener(this);
magenta.addActionListener(this);
jaune.addActionListener(this);
}
public void actionPerformed(ActionEvent evenement)
{
String test;
test = evenement.getActionCommand();
if(test.equals("Cyan"))
{
this.setBackground(Color.CYAN);
}
if(test.equals("Magenta"))
{
this.setBackground(Color.MAGENTA);
}
if(test.equals("Jaune"))
{
this.setBackground(Color.YELLOW);
}
}
}