BUT2/DEV/DEV3.2/Controle_Machine_Blanc/Q1_Annulation/Fenetre.java

40 lines
1.3 KiB
Java
Raw Normal View History

import javax.swing.*;
import java.awt.*;
2023-12-19 19:50:02 +01:00
import java.util.Deque;
import java.util.ArrayDeque;
public class Fenetre extends JFrame{
2023-12-19 19:50:02 +01:00
private Deque<JCheckBox> historique;
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<>();
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];
int i;
2023-12-19 19:50:02 +01:00
this.setLayout(new GridLayout(nbIngredient+1,1));
for (i=0; i<nbIngredient; i++){
2023-12-19 19:50:02 +01:00
listeCoche[i] = new JCheckBox(listeIngredient[i].name());
listeCoche[i].addItemListener(evenementIngredient);
this.add(listeCoche[i]);
}
2023-12-19 19:50:02 +01:00
EvenementRetour evenementRetour = new EvenementRetour(this.historique);
retour.setEnabled(false);
retour.addActionListener(evenementRetour);
this.add(retour);
}
}