Ajout TP09 / TP10
This commit is contained in:
BIN
APL2.1/TP10/Fond/Fond.class
Normal file
BIN
APL2.1/TP10/Fond/Fond.class
Normal file
Binary file not shown.
50
APL2.1/TP10/Fond/Fond.java
Normal file
50
APL2.1/TP10/Fond/Fond.java
Normal file
@@ -0,0 +1,50 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Fond {
|
||||
|
||||
public static void main(String[] args) {
|
||||
JFrame f = new JFrame("Fond");
|
||||
f.setSize(200, 200);
|
||||
f.setLocation(100, 100);
|
||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
f.setLayout(new GridLayout(1, 3));
|
||||
|
||||
JButton b1 = new JButton("Jaune");
|
||||
JButton b2 = new JButton("Cyan");
|
||||
JButton b3 = new JButton("Magenta");
|
||||
|
||||
Observer observer = new Observer();
|
||||
|
||||
b1.addActionListener(observer);
|
||||
b2.addActionListener(observer);
|
||||
b3.addActionListener(observer);
|
||||
|
||||
f.add(b1);
|
||||
f.add(b2);
|
||||
f.add(b3);
|
||||
|
||||
f.setVisible(true);
|
||||
}
|
||||
}
|
||||
BIN
APL2.1/TP10/Fond/Observer.class
Normal file
BIN
APL2.1/TP10/Fond/Observer.class
Normal file
Binary file not shown.
Reference in New Issue
Block a user