update
This commit is contained in:
18
DEV/DEV2.1/TP08_Evenement/Q5_Commande/Fond.java~
Normal file
18
DEV/DEV2.1/TP08_Evenement/Q5_Commande/Fond.java~
Normal file
@@ -0,0 +1,18 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Fond{
|
||||
public static void main(String[] args) {
|
||||
JButton boutonCyan = new JButton("Cyan");
|
||||
JButton boutonMagenta = new JButton("Magenta");
|
||||
JButton boutonJaune = new JButton("Jaune");
|
||||
JButton[] boutonList = {boutonCyan,boutonMagenta,boutonJaune};
|
||||
FondEvent fenetreClass = new FondEvent(boutonList);
|
||||
|
||||
fenetreClass.fenetre();
|
||||
|
||||
boutonCyan.addActionListener(fenetreClass);
|
||||
boutonMagenta.addActionListener(fenetreClass);
|
||||
boutonJaune.addActionListener(fenetreClass);
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV2.1/TP08_Evenement/Q5_Commande/FondEvent.class
Normal file
BIN
DEV/DEV2.1/TP08_Evenement/Q5_Commande/FondEvent.class
Normal file
Binary file not shown.
30
DEV/DEV2.1/TP08_Evenement/Q5_Commande/FondEvent.java
Normal file
30
DEV/DEV2.1/TP08_Evenement/Q5_Commande/FondEvent.java
Normal file
@@ -0,0 +1,30 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class FondEvent implements ActionListener{
|
||||
public JPanel panneau;
|
||||
public JTextField champsSaisis;
|
||||
|
||||
public FondEvent(JPanel contenu){
|
||||
this.champsSaisis = new JTextField();
|
||||
this.champsSaisis.setPreferredSize(new Dimension(200,20));
|
||||
this.panneau = contenu;
|
||||
this.panneau.add(this.champsSaisis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent evenement){
|
||||
String couleur = evenement.getActionCommand();
|
||||
if (couleur.equals("Cyan")){
|
||||
panneau.setBackground(Color.CYAN);
|
||||
}
|
||||
if (couleur.equals("Magenta")){
|
||||
panneau.setBackground(Color.MAGENTA);
|
||||
}
|
||||
if (couleur.equals("Jaune")){
|
||||
panneau.setBackground(Color.YELLOW);
|
||||
}
|
||||
this.champsSaisis.setText("");
|
||||
}
|
||||
}
|
||||
25
DEV/DEV2.1/TP08_Evenement/Q5_Commande/FondEvent.java~
Normal file
25
DEV/DEV2.1/TP08_Evenement/Q5_Commande/FondEvent.java~
Normal file
@@ -0,0 +1,25 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class FondEvent implements ActionListener{
|
||||
public JPanel panneau;
|
||||
|
||||
public FondEvent(JPanel contenu){
|
||||
this.panneau = contenu;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent evenement){
|
||||
String couleur = evenement.getActionCommand();
|
||||
if (couleur=="Cyan"){
|
||||
panneau.setBackground(Color.CYAN);
|
||||
}
|
||||
if (couleur=="Magenta"){
|
||||
panneau.setBackground(Color.MAGENTA);
|
||||
}
|
||||
if (couleur=="Jaune"){
|
||||
panneau.setBackground(Color.YELLOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
30
DEV/DEV2.1/TP08_Evenement/Q5_Commande/Q1Main.java~
Normal file
30
DEV/DEV2.1/TP08_Evenement/Q5_Commande/Q1Main.java~
Normal file
@@ -0,0 +1,30 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Q1Main{
|
||||
public static void main(String[] args) {
|
||||
JFrame fenetre = new JFrame();
|
||||
fenetre.setSize(500, 300);
|
||||
fenetre.setLocation(0, 0);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
JButton boutonCyan = new JButton("Cyan");
|
||||
JButton boutonMagenta = new JButton("Magenta");
|
||||
JButton boutonJaune = new JButton("Jaune");
|
||||
|
||||
JPanel contenu = new JPanel();
|
||||
contenu.add(boutonCyan);
|
||||
contenu.add(boutonMagenta);
|
||||
contenu.add(boutonJaune);
|
||||
|
||||
FondEvent evenementBouton = new FondEvent(contenu);
|
||||
|
||||
boutonCyan.addActionListener(evenementBouton);
|
||||
boutonMagenta.addActionListener(evenementBouton);
|
||||
boutonJaune.addActionListener(evenementBouton);
|
||||
|
||||
fenetre.add(contenu);
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV2.1/TP08_Evenement/Q5_Commande/Q5Main.class
Normal file
BIN
DEV/DEV2.1/TP08_Evenement/Q5_Commande/Q5Main.class
Normal file
Binary file not shown.
20
DEV/DEV2.1/TP08_Evenement/Q5_Commande/Q5Main.java
Normal file
20
DEV/DEV2.1/TP08_Evenement/Q5_Commande/Q5Main.java
Normal file
@@ -0,0 +1,20 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Q5Main{
|
||||
public static void main(String[] args) {
|
||||
JFrame fenetre = new JFrame();
|
||||
fenetre.setSize(500, 300);
|
||||
fenetre.setLocation(0, 0);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
JPanel contenu = new JPanel();
|
||||
FondEvent evenementBouton = new FondEvent(contenu);
|
||||
|
||||
evenementBouton.champsSaisis.addActionListener(evenementBouton);
|
||||
|
||||
fenetre.add(contenu);
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
||||
24
DEV/DEV2.1/TP08_Evenement/Q5_Commande/Q5Main.java~
Normal file
24
DEV/DEV2.1/TP08_Evenement/Q5_Commande/Q5Main.java~
Normal file
@@ -0,0 +1,24 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Q5Main{
|
||||
public static void main(String[] args) {
|
||||
JFrame fenetre = new JFrame();
|
||||
fenetre.setSize(500, 300);
|
||||
fenetre.setLocation(0, 0);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
JTextField champsSaisis = new JTextField();
|
||||
|
||||
JPanel contenu = new JPanel();
|
||||
contenu.add(champsSaisis);
|
||||
|
||||
FondEvent evenementBouton = new FondEvent(contenu);
|
||||
|
||||
champsSaisis.addActionListener(evenementBouton);
|
||||
|
||||
fenetre.add(contenu);
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user