APL/APL2.1/TP8/Fond/Fond.java

49 lines
1.3 KiB
Java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Fond implements ActionListener
{
public static JButton bouton1, bouton2, bouton3;
private JPanel panneau;
public Fond() {
JFrame fenetre = new JFrame();
fenetre.setSize(300, 300);
fenetre.setLocation(100, 100);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panneau = new JPanel();
bouton1 = new JButton("Cyan");
bouton1.addActionListener(this);
bouton2 = new JButton("Magenta");
bouton2.addActionListener(this);
bouton3 = new JButton("Jaune");
bouton3.addActionListener(this);
panneau.add(bouton1);
panneau.add(bouton2);
panneau.add(bouton3);
fenetre.add(panneau);
fenetre.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if (source == bouton1)
{
panneau.setBackground(Color.CYAN);
}
else if (source == bouton2)
{
panneau.setBackground(Color.MAGENTA);
}
else if (source == bouton3)
{
panneau.setBackground(Color.YELLOW);
}
panneau.repaint();
}
public static void main(String[] args)
{
new Fond();
}
}