58 lines
1.6 KiB
Java
58 lines
1.6 KiB
Java
import java.awt.*;
|
|
import javax.swing.*;
|
|
import java.awt.event.ActionListener;
|
|
import java.awt.event.ActionEvent;
|
|
|
|
public class Fond {
|
|
public static void main(String[] args) {
|
|
try {
|
|
try {
|
|
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
|
|
} catch (ClassNotFoundException e) {
|
|
}
|
|
} catch (InstantiationException e2) {
|
|
} catch (IllegalAccessException e3) {
|
|
} catch (UnsupportedLookAndFeelException e4) {
|
|
} // On constate que les boutons changent d'apparence
|
|
catch (ClassCastException e5) {
|
|
System.out.println("Nom de manager incorrect");
|
|
} // Les boutons restent comme avant
|
|
|
|
JFrame fenetre = new JFrame();
|
|
fenetre.setSize(300,200);
|
|
fenetre.setLocation(100,100);
|
|
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
fenetre.setLayout(new GridLayout(1, 1));
|
|
|
|
JPanel panneau = new JPanel();
|
|
|
|
JButton bouton1 = new JButton("Cyan");
|
|
JButton bouton2 = new JButton("Magenta");
|
|
JButton bouton3 = new JButton("Jaune");
|
|
|
|
bouton1.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent evenement) {
|
|
panneau.setBackground(Color.CYAN);
|
|
}
|
|
});
|
|
|
|
bouton2.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent evenement) {
|
|
panneau.setBackground(Color.RED);
|
|
}
|
|
});
|
|
|
|
bouton3.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent evenement) {
|
|
panneau.setBackground(Color.MAGENTA);
|
|
}
|
|
});
|
|
|
|
panneau.add(bouton1);
|
|
panneau.add(bouton2);
|
|
panneau.add(bouton3);
|
|
|
|
fenetre.add(panneau);
|
|
fenetre.setVisible(true);
|
|
}
|
|
} |