1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| package Vue.produit;
import Controleur.produit.ProduitAjoutCon;
import Modele.Categorie;
import java.awt.*;
import java.util.ArrayList;
import javax.swing.*;
public class ProduitAjoutPanel extends JPanel{
private JLabel nomLabel, catLabel;
private JTextField nom;
private JComboBox cat;
private DefaultComboBoxModel modeleBox;
private JButton ajouter;
private ProduitAjoutCon con;
private ArrayList<Categorie> listeCategorie;
private GridBagConstraints gbc;
public ProduitAjoutPanel(ProduitAjoutCon con) {
this.con = con;
con.setPanel(this);
this.setLayout(new GridBagLayout());
gbc = new GridBagConstraints();
nomLabel = new JLabel("Nom du produit :");
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.anchor = GridBagConstraints.BASELINE_LEADING;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(0, 0, 10, 10);
this.add(nomLabel, gbc);
nom = new JTextField(15);
gbc.gridx = 1;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.anchor = GridBagConstraints.BASELINE_LEADING;
gbc.fill = GridBagConstraints.HORIZONTAL;
this.add(nom, gbc);
ajouter = new JButton("Ajouter");
gbc.gridx = 1;
gbc.gridy = 5;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.anchor = GridBagConstraints.BASELINE_LEADING;
gbc.fill = GridBagConstraints.HORIZONTAL;
this.add(ajouter, gbc);
ajouter.addActionListener(con);
}
public JTextField getNom() {
return nom;
}
public void setNom(JTextField nom) {
this.nom = nom;
}
public void reset() {
this.nom.setText("");
}
public void setListe(ArrayList<Categorie> listeCategorie) {
this.listeCategorie = listeCategorie;
}
public void afficheCombo(boolean b) {
if(b) {
catLabel = new JLabel("Catégorie :");
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.anchor = GridBagConstraints.BASELINE_LEADING;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(0, 0, 10, 10);
this.add(catLabel, gbc);
modeleBox = new DefaultComboBoxModel(listeCategorie.toArray());
cat = new JComboBox(modeleBox);
gbc.gridx = 1;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.anchor = GridBagConstraints.BASELINE_LEADING;
gbc.fill = GridBagConstraints.HORIZONTAL;
this.add(cat, gbc);
}
}
} |
Partager