diff --git a/APL2.1/TP8/Radio/ObservateurRadio.class b/APL2.1/TP8/Radio/ObservateurRadio.class new file mode 100644 index 0000000..832b9e7 Binary files /dev/null and b/APL2.1/TP8/Radio/ObservateurRadio.class differ diff --git a/APL2.1/TP8/Radio/ObservateurRadio.java b/APL2.1/TP8/Radio/ObservateurRadio.java new file mode 100644 index 0000000..3e2b8e1 --- /dev/null +++ b/APL2.1/TP8/Radio/ObservateurRadio.java @@ -0,0 +1,34 @@ + import java.awt.*; + import javax.swing.*; + import java.awt.event.*; + + public class ObservateurRadio implements ActionListener + { + private JPanel panneau; + + public ObservateurRadio(JPanel panneau) + { + this.panneau = panneau; + } + + @Override + public void actionPerformed(ActionEvent e) + { + String action = e.getActionCommand(); + + if (action == "CYAN") + { + panneau.setBackground(Color.CYAN); + } + + else if (action == "MAGENTA") + { + panneau.setBackground(Color.MAGENTA); + } + + else if (action == "YELLOW") + { + panneau.setBackground(Color.YELLOW); + } + } + } diff --git a/APL2.1/TP8/Radio/Radio.class b/APL2.1/TP8/Radio/Radio.class new file mode 100644 index 0000000..f28c5a0 Binary files /dev/null and b/APL2.1/TP8/Radio/Radio.class differ diff --git a/APL2.1/TP8/Radio/Radio.java b/APL2.1/TP8/Radio/Radio.java new file mode 100644 index 0000000..f38f856 --- /dev/null +++ b/APL2.1/TP8/Radio/Radio.java @@ -0,0 +1,42 @@ + 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); + } + }