DEV/DEV2.1/TP5/Fond.java

32 lines
788 B
Java
Raw Normal View History

2023-04-26 11:00:04 +02:00
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);
}
}
}