34 lines
1.1 KiB
Java
34 lines
1.1 KiB
Java
|
import javax.swing.*;
|
||
|
import java.awt.*;
|
||
|
import java.awt.event.*;
|
||
|
|
||
|
public class EvenementRetour implements ActionListener{
|
||
|
|
||
|
private PileIngredient historique;
|
||
|
private Coche[] listeCoche;
|
||
|
private EvenementIngredient evenementIngredient;
|
||
|
|
||
|
|
||
|
public EvenementRetour(PileIngredient historique, Coche[] listeCoche, EvenementIngredient evenementIngredient){
|
||
|
this.historique = historique;
|
||
|
this.listeCoche = listeCoche;
|
||
|
this.evenementIngredient = evenementIngredient;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void actionPerformed(ActionEvent e){
|
||
|
Ingredient 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);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|