fin du cotrole blanc dev32
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
import javax.swing.JCheckBox;
|
||||
|
||||
public class Coche extends JCheckBox{
|
||||
|
||||
private Ingredient valeur;
|
||||
|
||||
public Coche(Ingredient valeur){
|
||||
super(valeur.name());
|
||||
this.valeur = valeur;
|
||||
}
|
||||
|
||||
public Ingredient getValeur(){
|
||||
return this.valeur;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -1,21 +1,22 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.Deque;
|
||||
|
||||
public class EvenementIngredient implements ItemListener{
|
||||
|
||||
private PileIngredient historiqueChoix;
|
||||
private Deque<JCheckBox> historiqueChoix;
|
||||
private JButton boutonRetour;
|
||||
|
||||
public EvenementIngredient(PileIngredient historiqueChoix, JButton boutonRetour){
|
||||
public EvenementIngredient(Deque<JCheckBox> historiqueChoix, JButton boutonRetour){
|
||||
this.historiqueChoix = historiqueChoix;
|
||||
this.boutonRetour = boutonRetour;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e){
|
||||
Coche coche = (Coche) e.getSource();
|
||||
this.historiqueChoix.push(coche.getValeur());
|
||||
JCheckBox coche = (JCheckBox) e.getSource();
|
||||
this.historiqueChoix.push(coche);
|
||||
this.boutonRetour.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -1,33 +1,25 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.Deque;
|
||||
|
||||
public class EvenementRetour implements ActionListener{
|
||||
|
||||
private PileIngredient historique;
|
||||
private Coche[] listeCoche;
|
||||
private EvenementIngredient evenementIngredient;
|
||||
private Deque<JCheckBox> historique;
|
||||
|
||||
|
||||
public EvenementRetour(PileIngredient historique, Coche[] listeCoche, EvenementIngredient evenementIngredient){
|
||||
public EvenementRetour(Deque<JCheckBox> historique){
|
||||
this.historique = historique;
|
||||
this.listeCoche = listeCoche;
|
||||
this.evenementIngredient = evenementIngredient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e){
|
||||
Ingredient dernierChoisis = this.historique.pop();
|
||||
JCheckBox dernierChoisis = this.historique.pop();
|
||||
JButton boutonRetour = (JButton) e.getSource();
|
||||
for (Coche coche : this.listeCoche){
|
||||
if (coche.getValeur() == dernierChoisis){
|
||||
coche.removeItemListener(evenementIngredient);
|
||||
coche.setSelected(!coche.isSelected());
|
||||
coche.addItemListener(evenementIngredient);
|
||||
if (historique.isEmpty()){
|
||||
boutonRetour.setEnabled(false);
|
||||
}
|
||||
}
|
||||
dernierChoisis.setSelected(!dernierChoisis.isSelected()); // cette ligne declenche l'evenementIngredient
|
||||
this.historique.pop(); // il faut donc retirer le dernier ingredient ajouter malencontreusement
|
||||
if (historique.isEmpty()){
|
||||
boutonRetour.setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
DEV/DEV3.2/Controle_Machine_Blanc/Q1_Annulation/Fenetre.class
Normal file
BIN
DEV/DEV3.2/Controle_Machine_Blanc/Q1_Annulation/Fenetre.class
Normal file
Binary file not shown.
@@ -1,9 +1,11 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Deque;
|
||||
import java.util.ArrayDeque;
|
||||
|
||||
public class Fenetre extends JFrame{
|
||||
|
||||
private PileIngredient historique;
|
||||
private Deque<JCheckBox> historique;
|
||||
|
||||
public Fenetre(){
|
||||
super();
|
||||
@@ -11,7 +13,7 @@ public class Fenetre extends JFrame{
|
||||
this.setSize(500, 300);
|
||||
this.setLocation(0, 0);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.historique = new PileIngredient();
|
||||
this.historique = new ArrayDeque<>();
|
||||
this.addIngredient();
|
||||
}
|
||||
|
||||
@@ -20,17 +22,17 @@ public class Fenetre extends JFrame{
|
||||
EvenementIngredient evenementIngredient = new EvenementIngredient(this.historique, retour);
|
||||
Ingredient[] listeIngredient = Ingredient.values();
|
||||
int nbIngredient = listeIngredient.length;
|
||||
Coche[] listeCoche = new Coche[nbIngredient];
|
||||
JCheckBox[] listeCoche = new JCheckBox[nbIngredient];
|
||||
int i;
|
||||
this.setLayout(new GridLayout(1,nbIngredient+1));
|
||||
this.setLayout(new GridLayout(nbIngredient+1,1));
|
||||
|
||||
for (i=0; i<nbIngredient; i++){
|
||||
listeCoche[i] = new Coche(listeIngredient[i]);
|
||||
listeCoche[i] = new JCheckBox(listeIngredient[i].name());
|
||||
listeCoche[i].addItemListener(evenementIngredient);
|
||||
this.add(listeCoche[i]);
|
||||
}
|
||||
|
||||
EvenementRetour evenementRetour = new EvenementRetour(this.historique, listeCoche, evenementIngredient);
|
||||
EvenementRetour evenementRetour = new EvenementRetour(this.historique);
|
||||
retour.setEnabled(false);
|
||||
retour.addActionListener(evenementRetour);
|
||||
this.add(retour);
|
||||
|
||||
BIN
DEV/DEV3.2/Controle_Machine_Blanc/Q1_Annulation/Ingredient.class
Normal file
BIN
DEV/DEV3.2/Controle_Machine_Blanc/Q1_Annulation/Ingredient.class
Normal file
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
enum Ingredient{
|
||||
SALADE,
|
||||
TOMATES,
|
||||
OIGNONS
|
||||
OIGNONS,
|
||||
}
|
||||
BIN
DEV/DEV3.2/Controle_Machine_Blanc/Q1_Annulation/Main.class
Normal file
BIN
DEV/DEV3.2/Controle_Machine_Blanc/Q1_Annulation/Main.class
Normal file
Binary file not shown.
@@ -2,7 +2,7 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Q4Main{
|
||||
public class Main{
|
||||
public static void main(String[] args) {
|
||||
|
||||
Fenetre fenetre = new Fenetre();
|
||||
@@ -1,23 +0,0 @@
|
||||
import java.util.*;
|
||||
|
||||
public class PileIngredient{
|
||||
|
||||
private Deque<Ingredient> pile;
|
||||
|
||||
public PileIngredient(){
|
||||
this.pile = new ArrayDeque<>();
|
||||
}
|
||||
|
||||
public void push(Ingredient valeur){
|
||||
this.pile.push(valeur);
|
||||
}
|
||||
|
||||
public Ingredient pop(){
|
||||
return this.pile.pop();
|
||||
|
||||
}
|
||||
|
||||
public boolean isEmpty(){
|
||||
return this.pile.isEmpty();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user