62 lines
1.6 KiB
Java
62 lines
1.6 KiB
Java
|
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 Apparences {
|
||
|
|
||
|
public static void main(String[] args) {
|
||
|
try {
|
||
|
UIManager.setLookAndFeel("toto");
|
||
|
} catch (ClassNotFoundException e) {
|
||
|
System.err.println("CONCENTRE TOI NOM DE DIEU !!");
|
||
|
|
||
|
} catch (ClassCastException e) {
|
||
|
System.err.println("Tu pourrais te concentrer et coder bien ?");
|
||
|
|
||
|
} catch (Exception e) {
|
||
|
System.err.println("Prout !");
|
||
|
}
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
}
|