DEV/DEV2.1/TP7/Fond.java

35 lines
810 B
Java
Raw Normal View History

2023-04-27 11:24:21 +02:00
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
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);
}
}
}