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 189 190 191 192 193 194 195
| package com.projet.checklist.gui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import com.baptiste.checklist.logic.Categorie;
import com.baptiste.checklist.logic.Liste;
import com.baptiste.checklist.logic.Produit;
public class Fenetre extends JFrame implements ActionListener
{
private static final long serialVersionUID = 1L;
private JPanel large = new JPanel();
private JButton save = new JButton("Save");
private JButton load = new JButton("Load");
private JButton addCategory = new JButton("Add");
private JButton addProduct = new JButton("Add");
private JButton rmvCategory = new JButton("Delete");
private JButton rmvProduct = new JButton("Delete");
private JLabel category = new JLabel("Category");
private JLabel product = new JLabel("Product");
private JLabel text = new JLabel("Liste des courses");
private Liste list;
public Fenetre()
{
try
{
this.setTitle("Projet de validation");
this.setSize(630, 520);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addProduct.addActionListener(new addProductListenner());
addCategory.addActionListener(new addCategoryListenner());
load.addActionListener(new loadListenner());
rmvCategory.addActionListener(new rmvCategoryListenner());
rmvProduct.addActionListener(new rmvProductListenner());
save.addActionListener(new saveListenner());
large.setLayout(new BorderLayout());
JPanel bot = new JPanel();
bot.add(load);
bot.add(save);
JPanel top = new JPanel();
top.add(text);
// TABLEAU //
JPanel center = new JPanel();
JTable table = new JTable();
JScrollPane tableContainer = new JScrollPane(table);
center.add(tableContainer, BorderLayout.CENTER); // ERREUR //
// AJOUT + SUP //
JPanel center_e = new JPanel();
JPanel center_w = new JPanel();
center_e.setLayout(new GridLayout(3, 0, 50, 115));
center_w.setLayout(new GridLayout(3, 0, 50, 115));
center_e.add(category);
category.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
center_w.add(product);
product.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
center_e.add(addCategory);
center_e.add(rmvCategory);
center_e.setBackground(Color.GRAY);
center_w.add(addProduct);
center_w.add(rmvProduct);
center_w.setBackground(Color.GRAY);
// POSITION JPANEL //
large.add(bot, BorderLayout.SOUTH);
large.add(center, BorderLayout.CENTER);
large.add(center_w, BorderLayout.EAST);
large.add(center_e, BorderLayout.WEST);
large.add(top, BorderLayout.NORTH);
large.setBackground(Color.WHITE);
this.setContentPane(large);
}
catch(NullPointerException e)
{
System.out.print("NullPointerException caught");
}
}
class addProductListenner implements ActionListener
{
public void actionPerformed(ActionEvent arg0)
{
if(arg0.getSource() == addProduct)
{
String[] categorie = {"Fruits", "Légumes", "Ajouter une catégorie"};
JOptionPane addP = new JOptionPane(), addP2 = new JOptionPane(), addP3 = new JOptionPane(), addP4 = new JOptionPane(),addP5 = new JOptionPane();
String produit = addP.showInputDialog(null, "Nom du produit","Ajouter un produit", JOptionPane.QUESTION_MESSAGE);
String marque = addP3.showInputDialog(null, "Marque ?","Ajouter un produit", JOptionPane.QUESTION_MESSAGE);
String quantite = addP4.showInputDialog(null, "Quantité ? ","Ajouter un produit", JOptionPane.QUESTION_MESSAGE);
Object cat = (String)addP2.showInputDialog(null, "Nom de la catégorie associée","Association",JOptionPane.QUESTION_MESSAGE,null,categorie,categorie[2]);
Produit produit1 = new Produit(produit, marque, quantite, false);
((Categorie) cat).addProduct(produit1);
// Si la personne clique sur autre le produit s'ajoute dans une catégorie crée
if(cat == "Ajouter une catégorie"){
String ajoutC = addP5.showInputDialog(null, "Catégorie à ajouter", JOptionPane.QUESTION_MESSAGE);
/*Categorie ajoutC1 = new Categorie(cat);
Produit produit = new Produit(produit, marque, quantite, false)
ajoutC1.addProduct(produit);
}
else
Produit produit = new Produit(produit, marque, quantite, false)
cat.addProduct(produit) */
addP3.showMessageDialog(null, "Votre produit a bien été ajouté");}
}
}
}
class rmvProductListenner implements ActionListener
{
public void actionPerformed(ActionEvent arg0)
{
if(arg0.getSource() == rmvProduct)
{
JOptionPane rmvP = new JOptionPane(), rmvP2 = new JOptionPane();
Object produit = rmvP.showInputDialog(null, "Nom du produit a retirer","Suppression de produit", JOptionPane.QUESTION_MESSAGE);
rmvP2.showMessageDialog(null, "L'élement " + produit + " a été supprimé");
// Via l'indice que prend le positionnement de mon produit le supprimer à l'aide d'indexOf et remove""
}
}
}
class addCategoryListenner implements ActionListener
{
public void actionPerformed(ActionEvent arg0)
{
if(arg0.getSource() == addCategory)
{
JOptionPane addC = new JOptionPane(), addC2 = new JOptionPane();
Object add = addC.showInputDialog(null, "Nom de la catégorie","Ajouter la catégorie", JOptionPane.QUESTION_MESSAGE);
Categorie categorie1 = new Categorie(add);
list.addCategory(add);
JOptionPane.showMessageDialog(null, "La catégorie a été ajoutée");
}
}
}
class rmvCategoryListenner implements ActionListener
{
public void actionPerformed(ActionEvent arg0)
{
if(arg0.getSource() == rmvCategory)
{
JOptionPane rmvC = new JOptionPane(), rmvC2 = new JOptionPane();
Object categorie = rmvC.showInputDialog(null, "Nom de la catégorie a retirer","Suppression de produit", JOptionPane.QUESTION_MESSAGE);
rmvC2.showMessageDialog(null, "L'élement " + categorie + " a été supprimé");
// Via l'indice que prend le positionnement de mon produit le supprimer à l'aide d'indexOf et remove""
}
}
}
class loadListenner implements ActionListener
{
public void actionPerformed(ActionEvent arg0)
{
JOptionPane load = new JOptionPane();
list.getListeFromFileName("Ma_Liste.isep");
load.showMessageDialog(null, "Votre liste a été chargéé"); // Récupère bien un objet
}
}
class saveListenner implements ActionListener
{
public void actionPerformed(ActionEvent arg0)
{
JOptionPane save = new JOptionPane();
list.saveList(list);
save.showMessageDialog(null, "Votre liste a été sauvegardée");
}
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
} |
Partager