This commit is contained in:
Emmanuel Srivastava
2025-03-05 20:44:11 +01:00
parent 1384bb65e9
commit 79cf818d89
2 changed files with 42 additions and 55 deletions

View File

@@ -1,11 +1,12 @@
import java.awt.*;
import javax.swing.*;
public class Fond {
public class Fond extends JPanel implements ActionListener {
private JButton Cyan, Magenta, Jaune;
public Fond() {
this.setLayout(null);
this.Cyan = new JButton("Cyan");
this.Magenta = new JButton("Magenta");
this.Jaune = new JButton("Jaune");
@@ -18,19 +19,19 @@ public class Fond {
this.Magenta.addActionListener(this);
this.Jaune.addActionListener(this);
frame.add(this.Cyan);
frame.add(this.Magenta);
frame.add(this.Jaune);
this.add(this.Cyan);
this.add(this.Magenta);
this.add(this.Jaune);
}
@Override
public void actionPerformed(ActionEvent evenement) {
if (evenement.getSource() == this.Cyan) {
frame.setBackground(Color.CYAN);
this.setBackground(Color.CYAN);
} else if (evenement.getSource() == this.Magenta) {
frame.setBackground(Color.MAGENTA);
this.setBackground(Color.MAGENTA);
} else if (evenement.getSource() == this.Jaune) {
frame.setBackground(Color.JAUNE);
this.setBackground(Color.YELLOW);
}
}
}