37 lines
840 B
Java
37 lines
840 B
Java
|
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);
|
||
|
}
|
||
|
}
|
||
|
}
|