43 lines
1.2 KiB
Java
43 lines
1.2 KiB
Java
|
import java.awt.*;
|
||
|
import javax.swing.*;
|
||
|
import java.awt.event.*;
|
||
|
|
||
|
public class Radio
|
||
|
{
|
||
|
static public void main(String[] args)
|
||
|
{
|
||
|
JFrame fenetre = new JFrame();
|
||
|
fenetre.setSize(300, 300);
|
||
|
fenetre.setLocation(100, 100);
|
||
|
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||
|
|
||
|
JPanel panneau = new JPanel();
|
||
|
JPanel colorPanel = new JPanel();
|
||
|
ButtonGroup groupe = new ButtonGroup();
|
||
|
JRadioButton cyanBtn = new JRadioButton("CYAN");
|
||
|
JRadioButton magentaBtn = new JRadioButton("MAGENTA");
|
||
|
JRadioButton yellowBtn = new JRadioButton("YELLOW");
|
||
|
|
||
|
ObservateurRadio observateur = new ObservateurRadio(colorPanel);
|
||
|
|
||
|
panneau.setLayout(new GridLayout(3, 1));
|
||
|
|
||
|
panneau.add(cyanBtn);
|
||
|
panneau.add(magentaBtn);
|
||
|
panneau.add(yellowBtn);
|
||
|
|
||
|
groupe.add(cyanBtn);
|
||
|
groupe.add(magentaBtn);
|
||
|
groupe.add(yellowBtn);
|
||
|
|
||
|
cyanBtn.addActionListener(observateur);
|
||
|
magentaBtn.addActionListener(observateur);
|
||
|
yellowBtn.addActionListener(observateur);
|
||
|
|
||
|
fenetre.add(colorPanel);
|
||
|
fenetre.add(panneau, BorderLayout.SOUTH);
|
||
|
|
||
|
fenetre.setVisible(true);
|
||
|
}
|
||
|
}
|