Update DEV.2.1/TP/TP8-Evenements/1.Fond/Fond.java
This commit is contained in:
@@ -1,37 +1,38 @@
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.event.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
public class Fond extends JPanel implements ActionListener {
|
public class Fond extends JPanel implements ActionListener {
|
||||||
private JButton Cyan, Magenta, Jaune;
|
private JButton Cyan, Magenta, Jaune;
|
||||||
|
|
||||||
public Fond() {
|
public Fond() {
|
||||||
this.setLayout(null);
|
this.setLayout(null);
|
||||||
|
|
||||||
this.Cyan = new JButton("Cyan");
|
this.Cyan = new JButton("Cyan");
|
||||||
this.Magenta = new JButton("Magenta");
|
this.Magenta = new JButton("Magenta");
|
||||||
this.Jaune = new JButton("Jaune");
|
this.Jaune = new JButton("Jaune");
|
||||||
|
|
||||||
this.Cyan.setBounds(100,50,100,20);
|
this.Cyan.setBounds(100, 50, 100, 30);
|
||||||
this.Magenta.setBounds(220,50,100,20);
|
this.Magenta.setBounds(220, 50, 100, 30);
|
||||||
this.Jaune.setBounds(320,50,100,20);
|
this.Jaune.setBounds(340, 50, 100, 30);
|
||||||
|
|
||||||
this.Cyan.addActionListener(this);
|
this.Cyan.addActionListener(this);
|
||||||
this.Magenta.addActionListener(this);
|
this.Magenta.addActionListener(this);
|
||||||
this.Jaune.addActionListener(this);
|
this.Jaune.addActionListener(this);
|
||||||
|
|
||||||
this.add(this.Cyan);
|
this.add(this.Cyan);
|
||||||
this.add(this.Magenta);
|
this.add(this.Magenta);
|
||||||
this.add(this.Jaune);
|
this.add(this.Jaune);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent evenement) {
|
public void actionPerformed(ActionEvent evenement) {
|
||||||
if (evenement.getSource() == this.Cyan) {
|
if (evenement.getSource() == this.Cyan) {
|
||||||
this.setBackground(Color.CYAN);
|
this.setBackground(Color.CYAN);
|
||||||
} else if (evenement.getSource() == this.Magenta) {
|
} else if (evenement.getSource() == this.Magenta) {
|
||||||
this.setBackground(Color.MAGENTA);
|
this.setBackground(Color.MAGENTA);
|
||||||
} else if (evenement.getSource() == this.Jaune) {
|
} else if (evenement.getSource() == this.Jaune) {
|
||||||
this.setBackground(Color.YELLOW);
|
this.setBackground(Color.YELLOW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user