Files
DEV/DEV.2.1/TP/TP8-Evenements/3.Radio/Radio.java

40 lines
1.2 KiB
Java
Raw Normal View History

2025-03-05 21:36:58 +01:00
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);
2025-03-05 21:43:30 +01:00
this.Cyan = new JRadioButton("Cyan");
this.Magenta = new JRadioButton("Magenta");
this.Jaune = new JRadioButton("Jaune");
2025-03-05 21:36:58 +01:00
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
2025-03-05 21:47:00 +01:00
public void actionPerformed(ActionEvent evenement) {
2025-03-05 21:36:58 +01:00
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);
}
}
}