Files
DEV/DEV.2.1/TP/TP8-Evenements/3.Radio/Radio.java
Emmanuel Srivastava da33e5c8b3 update
2025-03-05 21:47:00 +01:00

40 lines
1.2 KiB
Java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Radio extends JPanel implements ActionListener {
private JRadioButton Cyan, Magenta, Jaune;
public Radio() {
super();
this.setLayout(null);
this.Cyan = new JRadioButton("Cyan");
this.Magenta = new JRadioButton("Magenta");
this.Jaune = new JRadioButton("Jaune");
this.Cyan.setBounds(100, 50, 100, 30);
this.Magenta.setBounds(220, 50, 100, 30);
this.Jaune.setBounds(340, 50, 100, 30);
this.Cyan.addActionListener(this);
this.Magenta.addActionListener(this);
this.Jaune.addActionListener(this);
this.add(this.Cyan);
this.add(this.Magenta);
this.add(this.Jaune);
}
@Override
public void actionPerformed(ActionEvent evenement) {
if (evenement.getSource() == this.Cyan) {
this.setBackground(Color.CYAN);
} else if (evenement.getSource() == this.Magenta) {
this.setBackground(Color.MAGENTA);
} else if (evenement.getSource() == this.Jaune) {
this.setBackground(Color.YELLOW);
}
}
}