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
| import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.Box;
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.border.LineBorder;
public class Onglet_commande extends JPanel implements ActionListener {
private JButton commander = new JButton("Commander et payer");
private JLabel res = new JLabel();
public Onglet_commande(){
// nos panels
JPanel pan1 = new JPanel();
JPanel pan1b = new JPanel();
JPanel pan2 = new JPanel();
JPanel pan3 = new JPanel();
JPanel princ = new JPanel();
// Pour les séparateurs
JPanel s1 = new JPanel();
JPanel s2 = new JPanel();
JPanel resultat = new JPanel();
// on les formes
pan1.setLayout(new BoxLayout(pan1, BoxLayout.LINE_AXIS));
pan1b.setLayout(new BoxLayout(pan1b, BoxLayout.LINE_AXIS));
pan2.setLayout(new BoxLayout(pan2, BoxLayout.LINE_AXIS));
pan3.setLayout(new BoxLayout(pan3, BoxLayout.LINE_AXIS));
princ.setLayout(new BoxLayout(princ, BoxLayout.PAGE_AXIS));
s1.setLayout(new BoxLayout(s1, BoxLayout.LINE_AXIS));
s2.setLayout(new BoxLayout(s2, BoxLayout.LINE_AXIS));
resultat.setLayout(new BoxLayout(resultat, BoxLayout.LINE_AXIS));
// les Label
JLabel pres = new JLabel("Bienvenue sur Fast Food and Fat");
pres.setFont(new Font("Tahoma", Font.BOLD, 30));
pres.setForeground(Color.ORANGE);
JLabel label_prod = new JLabel("Produits disponibles :");
label_prod.setFont(new Font("Tahoma", Font.BOLD, 20));
label_prod.setForeground(Color.GREEN);
JFormattedTextField nom_client = new JFormattedTextField();
nom_client.setBackground(Color.WHITE);
nom_client.setPreferredSize(new Dimension(120,30));
JLabel client = new JLabel("Nom du client :");
JLabel res = new JLabel("En attente d'affichage");
res.setSize(new Dimension(200,30));
// les séparateurs
JSeparator sep1 = new JSeparator();
JSeparator sep2 = new JSeparator();
// le Panneau Commande
DefaultListModel<String> listModel = new DefaultListModel<String>();
JList<String> liste_produit = new JList<String>();
liste_produit.setCellRenderer(new DefaultListCellRenderer());
liste_produit.setModel(listModel);
liste_produit.setBorder(new LineBorder(Color.GREEN));
JScrollPane scroll1 = new JScrollPane(liste_produit);
for (int i=ProduitsEnVente.getProducts().size()-1 ; i>=0;i--){
ProduitsEnVente.getInstance();
String temp = ProduitsEnVente.getProducts().get(i).getNom_produit();
listModel.addElement(temp);
}
// le Choix des boutons
commander.setBackground(Color.RED);
commander.addActionListener(this);
JButton reinit = new JButton("Réinitialiser la commande");
reinit.setBackground(Color.YELLOW);
pan1.add(pres);
s1.add(sep1);
pan1b.add(client);
pan1b.add(Box.createRigidArea(new Dimension(30,0)));
pan1b.add(nom_client);
s2.add(sep2);
pan2.add(label_prod);
pan2.add(Box.createRigidArea(new Dimension(30,0)));
pan2.add(scroll1);
pan3.add(commander);
pan3.add(Box.createRigidArea(new Dimension(30,0)));
pan3.add(reinit);
resultat.add(res);
// on ajout dans le JPanel
princ.add(pan1);
princ.add(Box.createRigidArea(new Dimension(0,30)));
princ.add(s1);
princ.add(Box.createRigidArea(new Dimension(0,30)));
princ.add(pan1b);
princ.add(Box.createRigidArea(new Dimension(0,30)));
princ.add(s2);
princ.add(Box.createRigidArea(new Dimension(0,30)));
princ.add(pan2);
princ.add(Box.createRigidArea(new Dimension(0,30)));
princ.add(pan3);
princ.add(Box.createRigidArea(new Dimension(0,30)));
princ.add(resultat);
add(princ);
}
public void paintComponent(Graphics g){
try {
Image img = ImageIO.read(new File("fastfood.jpg") );
g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
}
catch (IOException e){
e.printStackTrace();
}
}
public void actionPerformed(ActionEvent arg0) {
res.setText("Une commande vient d'être passée");
System.out.println("Une commande vient d'être passée");
}
} |
Partager