2023-12-18 21:05:47 +01:00
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.*;
|
2023-12-19 19:50:02 +01:00
|
|
|
import java.util.Deque;
|
|
|
|
import java.util.ArrayDeque;
|
2023-12-18 21:05:47 +01:00
|
|
|
|
|
|
|
public class Fenetre extends JFrame{
|
|
|
|
|
2023-12-19 19:50:02 +01:00
|
|
|
private Deque<JCheckBox> historique;
|
2023-12-18 21:05:47 +01:00
|
|
|
|
|
|
|
public Fenetre(){
|
|
|
|
super();
|
|
|
|
this.setTitle("Question1");
|
|
|
|
this.setSize(500, 300);
|
|
|
|
this.setLocation(0, 0);
|
|
|
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
2023-12-19 19:50:02 +01:00
|
|
|
this.historique = new ArrayDeque<>();
|
2023-12-18 21:05:47 +01:00
|
|
|
this.addIngredient();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addIngredient(){
|
|
|
|
JButton retour = new JButton("RETOUR");
|
|
|
|
EvenementIngredient evenementIngredient = new EvenementIngredient(this.historique, retour);
|
|
|
|
Ingredient[] listeIngredient = Ingredient.values();
|
|
|
|
int nbIngredient = listeIngredient.length;
|
2023-12-19 19:50:02 +01:00
|
|
|
JCheckBox[] listeCoche = new JCheckBox[nbIngredient];
|
2023-12-18 21:05:47 +01:00
|
|
|
int i;
|
2023-12-19 19:50:02 +01:00
|
|
|
this.setLayout(new GridLayout(nbIngredient+1,1));
|
2023-12-18 21:05:47 +01:00
|
|
|
|
|
|
|
for (i=0; i<nbIngredient; i++){
|
2023-12-19 19:50:02 +01:00
|
|
|
listeCoche[i] = new JCheckBox(listeIngredient[i].name());
|
2023-12-18 21:05:47 +01:00
|
|
|
listeCoche[i].addItemListener(evenementIngredient);
|
|
|
|
this.add(listeCoche[i]);
|
|
|
|
}
|
|
|
|
|
2023-12-19 19:50:02 +01:00
|
|
|
EvenementRetour evenementRetour = new EvenementRetour(this.historique);
|
2023-12-18 21:05:47 +01:00
|
|
|
retour.setEnabled(false);
|
|
|
|
retour.addActionListener(evenementRetour);
|
|
|
|
this.add(retour);
|
|
|
|
}
|
|
|
|
}
|