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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
| import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.text.NumberFormat;
import javax.imageio.ImageIO;
import javax.swing.BoxLayout;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
public class Onglet_stock extends JPanel {
/**
*
*/
public Onglet_stock(){
// nos panels et objets:
JPanel pan1 = new JPanel();
JPanel pan2 = new JPanel();
JPanel pan3 = new JPanel();
JPanel pan4 = new JPanel();
JPanel pan5 = new JPanel();
JPanel pan6 = new JPanel();
JPanel pan7 = new JPanel();
JPanel pan8 = new JPanel();
DefaultListModel<String> listModel = new DefaultListModel<String>();
DefaultListModel<String> listModel1 = new DefaultListModel<String>();
JList<String> liste_ingredient = new JList<String>();
JList<String> liste_produit_simple = new JList<String>();
JButton reinit = new JButton("MAJ Ingrédients");
JButton cuisiner = new JButton ("Acheter!");
JButton prod_simple = new JButton("MAJ Produits simples");
JSeparator sep1 = new JSeparator(SwingConstants.HORIZONTAL);
JSeparator sep2 = new JSeparator(SwingConstants.HORIZONTAL);
// on les formes
pan1.setLayout(new GridLayout(2, 3, 20, 20));
pan2.setLayout(new BoxLayout(pan2, BoxLayout.LINE_AXIS));
pan3.setLayout(new BoxLayout(pan3, BoxLayout.LINE_AXIS));
pan4.setLayout(new BoxLayout(pan4, BoxLayout.LINE_AXIS));
pan5.setLayout(new GridLayout(1, 2, 20, 20));
pan7.setLayout(new GridLayout(1, 3, 20, 20));
pan6.setLayout(new BoxLayout(pan6, BoxLayout.PAGE_AXIS));
//On autorise la sélection de plusieurs items dans la liste
liste_ingredient.setSelectionMode(0);
liste_produit_simple.setSelectionMode(0);
liste_ingredient.setVisibleRowCount(6);
liste_produit_simple.setVisibleRowCount(6);
JScrollPane scroll1 = new JScrollPane(liste_ingredient);
JScrollPane scroll2 = new JScrollPane(liste_produit_simple);
// le Label
JLabel pres = new JLabel("Approvisionnement du stock");
pres.setFont(new Font("Tahoma", Font.BOLD, 30));
pres.setForeground(Color.GREEN);
pan4.add(pres);
prod_simple.setPreferredSize(new Dimension(20,20));
// le panneau de préparation des produits (composés) lié à la méthode CuisinerProduits()
// On instancie tous nos objets
//Création de la liste
liste_ingredient.setCellRenderer(new DefaultListCellRenderer());
liste_ingredient.setModel(listModel);
liste_ingredient.setBorder(new LineBorder(Color.GREEN));
liste_produit_simple.setCellRenderer(new DefaultListCellRenderer());
liste_produit_simple.setModel(listModel1);
liste_produit_simple.setBorder(new LineBorder(Color.GREEN));
Ingredients.getInstance();
ProduitsEnVente.getInstance();
for (int i=Ingredients.getStockIngredients().size()-1 ; i>=0;i--){
String temp = Ingredients.getStockIngredients().get(i).getNom_ingredient();
listModel.addElement(temp);
}
for (int j=ProduitsEnVente.getProducts().size()-1 ; j>=0 ; j--){
String temp = ProduitsEnVente.getProducts().get(j).getNom_produit();
listModel1.addElement(temp);
}
JFormattedTextField nom_produit1 = new JFormattedTextField();
JLabel nom_produit=new JLabel("Ingrédients à commander");
JLabel prix_produit=new JLabel("Prix unitaire");
JLabel qte_produit=new JLabel("Quantité");
JLabel liste_ingred=new JLabel("Liste des ingrédients : ");
JLabel liste_prod = new JLabel("Liste des produits simples : ");
JFormattedTextField prix_produit1 = new JFormattedTextField();
JFormattedTextField qte_produit1 = new JFormattedTextField(NumberFormat.getIntegerInstance());
Font police = new Font("Arial", Font.BOLD, 14);
// On les modifie
nom_produit1.setFont(police);
prix_produit1.setFont(police);
qte_produit1.setFont(police);
nom_produit.setFont(police);
prix_produit.setFont(police);
qte_produit.setFont(police);
liste_ingred.setFont(police);
// Pour le 1er produit
nom_produit1.setPreferredSize(new Dimension(40, 30));
nom_produit1.setForeground(Color.ORANGE);
prix_produit1.setPreferredSize(new Dimension(40, 30));
prix_produit1.setForeground(Color.ORANGE);
qte_produit1.setPreferredSize(new Dimension(40, 30));
qte_produit1.setForeground(Color.ORANGE);
// On les ajuste dans le JPanel
pan1.add(nom_produit);
pan1.add(prix_produit);
pan1.add(qte_produit);
pan1.add(nom_produit1);
pan1.add(prix_produit1);
pan1.add(qte_produit1);
pan2.add(liste_ingred);
pan2.add(liste_ingredient);
pan5.add(cuisiner);
pan5.add(reinit);
pan4.add(pres);
pan7.add(liste_prod);
pan7.add(liste_produit_simple);
pan7.add(prod_simple);
// le Choix des boutons
// on ajoute dans le JPanel
pan6.add(pan4);
pan6.add(pan1);
pan6.add(sep1);
pan6.add(pan2);
pan6.add(sep2);
pan6.add(pan5);
pan6.add(pan7);
pan6.add(pan8);
add(pan6);
}
public void paintComponent(Graphics g){
try {
Image img = ImageIO.read(new File("stock.jpg") );
g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
}
catch (IOException e){
e.printStackTrace();
}
}
} |
Partager