Developpement/23DEV1.1/TPS2/TP01/Evènements/Radio.java

37 lines
840 B
Java
Raw Permalink Normal View History

2024-12-09 11:53:11 +01:00
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Radio extends JPanel implements ActionListener
{
public Radio()
{
super();
JRadioButton cyan = new JRadioButton("Cyan");
JRadioButton magenta = new JRadioButton("Magenta");
JRadioButton jaune = new JRadioButton("Jaune");
this.add(cyan);
this.add(magenta);
this.add(jaune);
cyan.addActionListener(this);
magenta.addActionListener(this);
jaune.addActionListener(this);
}
public void actionPerformed(ActionEvent evenement)
{
String test;
test = evenement.getActionCommand();
if(test.equals("Cyan"))
{
this.setBackground(Color.CYAN);
}
if(test.equals("Magenta"))
{
this.setBackground(Color.MAGENTA);
}
if(test.equals("Jaune"))
{
this.setBackground(Color.YELLOW);
}
}
}