APL/APL2.1/TP13/Memoire/Observer.java

24 lines
598 B
Java
Raw Normal View History

2022-05-16 17:29:36 +02:00
import java.awt.Color;
import java.awt.event.*;
import javax.swing.JPanel;
import javax.swing.JButton;
class Observer implements ActionListener {
public Observer() {
}
public void actionPerformed(ActionEvent evt) {
String name = evt.getActionCommand();
JPanel f = (JPanel)((JButton)evt.getSource()).getParent();
if (name == "Jaune") {
f.setBackground(Color.YELLOW);
} else if (name == "Cyan") {
f.setBackground(Color.CYAN);
} else if (name == "Magenta") {
f.setBackground(Color.MAGENTA);
}
}
}