TP10 fin
This commit is contained in:
BIN
APL2.1/TP10/Combinaison/Combinaison.class
Normal file
BIN
APL2.1/TP10/Combinaison/Combinaison.class
Normal file
Binary file not shown.
@@ -3,22 +3,36 @@ import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
class Observer implements ActionListener {
|
||||
public Observer() {
|
||||
boolean shouldY, shouldC, shouldM;
|
||||
|
||||
public Observer() {
|
||||
shouldY = false;
|
||||
shouldC = false;
|
||||
shouldM = false;
|
||||
}
|
||||
|
||||
private void updateColor(JPanel panel) {
|
||||
int r, g, b;
|
||||
|
||||
r = shouldC ? 0 : 255;
|
||||
g = shouldM ? 0 : 255;
|
||||
b = shouldY ? 0 : 255;
|
||||
|
||||
panel.setBackground(new Color(r, g ,b));
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
String name = evt.getActionCommand();
|
||||
JRadioButton rb = (JRadioButton)evt.getSource();
|
||||
JPanel f = (JPanel)rb.getParent();
|
||||
JRadioButton radioButton = (JRadioButton)evt.getSource();
|
||||
JPanel panel = (JPanel)radioButton.getParent();
|
||||
|
||||
if (name == "Jaune") {
|
||||
f.setBackground(Color.YELLOW);
|
||||
} else if (name == "Cyan") {
|
||||
f.setBackground(Color.CYAN);
|
||||
} else if (name == "Magenta") {
|
||||
f.setBackground(Color.MAGENTA);
|
||||
}
|
||||
boolean selected = radioButton.isSelected();
|
||||
|
||||
if (name == "Jaune") shouldY = selected;
|
||||
else if (name == "Magenta") shouldM = selected;
|
||||
else if (name == "Cyan") shouldC = selected;
|
||||
|
||||
updateColor(panel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,12 +44,11 @@ public class Combinaison {
|
||||
f.setLocation(100, 100);
|
||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
Observer observer = new Observer();
|
||||
JRadioButton b1 = new JRadioButton("Jaune");
|
||||
JRadioButton b2 = new JRadioButton("Cyan");
|
||||
JRadioButton b3 = new JRadioButton("Magenta");
|
||||
|
||||
Observer observer = new Observer();
|
||||
|
||||
b1.addActionListener(observer);
|
||||
b2.addActionListener(observer);
|
||||
b3.addActionListener(observer);
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user