Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.23 KB | None | 0 0
  1. // auteurs: Maud El-Hachem
  2. // 2015
  3. package drugware_v15;
  4.  
  5. import java.awt.Color;
  6. import java.awt.GridLayout;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.awt.event.WindowAdapter;
  10. import java.awt.event.WindowEvent;
  11. import java.util.Iterator;
  12. import java.util.List;
  13.  
  14. import javax.swing.JFrame;
  15. import javax.swing.JLabel;
  16. import javax.swing.JMenu;
  17. import javax.swing.JMenuBar;
  18. import javax.swing.JMenuItem;
  19. import javax.swing.JOptionPane;
  20. import javax.swing.JPanel;
  21. import javax.swing.JTextField;
  22.  
  23. public class Fenetre extends JFrame {
  24. private static final long serialVersionUID = 1L;
  25. private JMenuBar menuBar;
  26. private JMenu menuFic;
  27. private JMenu menuClients;
  28. private JMenu menuPresc;
  29. private JMenu menuMedic;
  30.  
  31. private JMenuItem itemFic1;
  32. private JMenuItem itemFic2;
  33. private JMenuItem itemFic3;
  34.  
  35. private JMenuItem itemClients1;
  36. private JMenuItem itemClients2;
  37.  
  38. private JMenuItem itemPresc1;
  39. private JMenuItem itemPresc2;
  40. private JMenuItem itemPresc3;
  41.  
  42. private JMenuItem itemMedic1;
  43. private JMenuItem itemMedic2;
  44.  
  45. private JTextField field1;
  46. private JTextField field2;
  47. private JTextField field3;
  48. private JTextField field4;
  49.  
  50. private Pharmacie pharma;
  51.  
  52. public Fenetre() {
  53. this.setSize(300, 200);
  54. this.setLocationRelativeTo(null);
  55. setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
  56.  
  57. menuBar = new JMenuBar();
  58. menuFic = new JMenu("Fichier");
  59. menuClients = new JMenu("Clients");
  60. menuPresc = new JMenu("Prescriptions");
  61. menuMedic = new JMenu("Médicaments");
  62.  
  63. itemFic1 = new JMenuItem("Charger les fichiers");
  64. itemFic2 = new JMenuItem("Mettre à jour les fichiers");
  65. itemFic3 = new JMenuItem("Quitter");
  66.  
  67. itemClients1 = new JMenuItem("Inscrire un nouveau client");
  68. itemClients2 = new JMenuItem("Afficher tous les clients");
  69.  
  70. itemPresc1 = new JMenuItem("Afficher les prescriptions d'un client");
  71. itemPresc2 = new JMenuItem("Servir une prescription");
  72. itemPresc3 = new JMenuItem("Nouvelle prescription");
  73.  
  74. itemMedic1 = new JMenuItem("Afficher tous les médicaments");
  75. itemMedic2 = new JMenuItem("Afficher si interaction");
  76.  
  77. field1 = new JTextField();
  78. field2 = new JTextField();
  79. field3 = new JTextField();
  80. field4 = new JTextField();
  81.  
  82. pharma = new Pharmacie();
  83. addWindowListener(new WindowAdapter() {
  84. public void windowClosing(WindowEvent e) {
  85. quitter();
  86. }
  87. });
  88. setVisible(true);
  89.  
  90. }
  91.  
  92. public void initMenus() {
  93.  
  94. // Menu fichier
  95. itemFic1.addActionListener(new BoutonFic1Listener());
  96. this.menuFic.add(itemFic1);
  97. itemFic2.addActionListener(new BoutonFic2Listener());
  98. this.menuFic.add(itemFic2);
  99.  
  100. // Ajout d'un séparateur
  101. this.menuFic.addSeparator();
  102. // si quitter
  103. itemFic3.addActionListener(new BoutonFic3Listener());
  104. this.menuFic.add(itemFic3);
  105.  
  106. // Menu Clients
  107. itemClients1.addActionListener(new BoutonClient1Listener());
  108. this.menuClients.add(itemClients1);
  109. itemClients2.addActionListener(new BoutonClient2Listener());
  110. this.menuClients.add(itemClients2);
  111.  
  112. // Menu Prescriptions
  113. itemPresc1.addActionListener(new BoutonPresc1Listener());
  114. this.menuPresc.add(itemPresc1);
  115. itemPresc2.addActionListener(new BoutonPresc2Listener());
  116. this.menuPresc.add(itemPresc2);
  117. itemPresc3.addActionListener(new BoutonPresc3Listener());
  118. this.menuPresc.add(itemPresc3);
  119.  
  120. // Menu Médicaments
  121. itemMedic1.addActionListener(new BoutonMedic1Listener());
  122. this.menuMedic.add(itemMedic1);
  123. itemMedic2.addActionListener(new BoutonMedic2Listener());
  124. this.menuMedic.add(itemMedic2);
  125.  
  126. this.menuBar.add(menuFic);
  127. this.menuBar.add(menuClients);
  128. this.menuBar.add(menuPresc);
  129. this.menuBar.add(menuMedic);
  130. this.setJMenuBar(menuBar);
  131. this.setVisible(true);
  132.  
  133. }
  134.  
  135. public class BoutonFic1Listener implements ActionListener {
  136. public void actionPerformed(ActionEvent arg0) {
  137. pharma.lireClients();
  138. pharma.lirePrescriptions();
  139. pharma.lireMedicaments();
  140. }
  141. }
  142.  
  143. public class BoutonFic2Listener implements ActionListener {
  144. public void actionPerformed(ActionEvent arg0) {
  145. pharma.ecrireClients();
  146. pharma.ecrirePrescriptions();
  147. }
  148. }
  149.  
  150. public class BoutonFic3Listener implements ActionListener {
  151. public void actionPerformed(ActionEvent arg0) {
  152. quitter();
  153. }
  154. }
  155.  
  156. public class BoutonClient1Listener implements ActionListener {
  157. public void actionPerformed(ActionEvent arg0) {
  158. String nom, prenom;
  159. String NAM = JOptionPane.showInputDialog(null,
  160. "Entre le numéro d'assurance maladie",
  161. "Numéro d'assurance maladie", JOptionPane.QUESTION_MESSAGE);
  162. if (NAM != null && NAM.length() > 0)
  163. if (pharma.siClientExiste(NAM))
  164. JOptionPane.showMessageDialog(null,
  165. "Ce numéro d'assurance maladie existe déjà",
  166. "Problème", JOptionPane.INFORMATION_MESSAGE);
  167. else {
  168. nom = JOptionPane.showInputDialog(null, "Entre le nom",
  169. "Nom", JOptionPane.QUESTION_MESSAGE);
  170. prenom = JOptionPane.showInputDialog(null,
  171. "Entre le prenom", "Prénom",
  172. JOptionPane.QUESTION_MESSAGE);
  173. if (nom != null && nom.length() > 0 && prenom != null
  174. && prenom.length() > 0)
  175. pharma.ajouterClient(NAM, nom, prenom);
  176. }
  177. }
  178. }
  179.  
  180. public class BoutonClient2Listener implements ActionListener {
  181. public void actionPerformed(ActionEvent arg0) {
  182. JFrame nouvelle = new JFrame("Clients");
  183. int nbClients = pharma.getLesClients().size();
  184. JPanel panneau = new JPanel();
  185. panneau.setLayout(new GridLayout(nbClients, 1));
  186. panneau.setBackground(Color.white);
  187. for (Iterator<Client> it = pharma.getLesClients().iterator(); it
  188. .hasNext();) {
  189. Client courant = it.next();
  190. JLabel label = new JLabel();
  191. label.setText("<html><p style='font-size:14px'>"
  192. + courant.afficherClient() + "</p></html>");
  193. panneau.add(label);
  194. }
  195. nouvelle.setContentPane(panneau);
  196. nouvelle.setSize(400, nbClients * 100);
  197. nouvelle.setVisible(true);
  198.  
  199. }
  200. }
  201.  
  202. public class BoutonPresc1Listener implements ActionListener {
  203. public void actionPerformed(ActionEvent arg0) {
  204. String NAM = JOptionPane.showInputDialog(null,
  205. "Entre le numéro d'assurance maladie",
  206. "Numéro d'assurance maladie", JOptionPane.QUESTION_MESSAGE);
  207. if (NAM != null && NAM.length() > 0) {
  208. List<Prescription> liste = pharma.getPrescriptionsClient(NAM);
  209. if (liste != null) {
  210. JFrame nouvelle = new JFrame("Prescription du client");
  211. int nbPresc = liste.size();
  212. JPanel panneau = new JPanel();
  213. panneau.setLayout(new GridLayout(nbPresc, 1));
  214. panneau.setBackground(Color.white);
  215. for (Iterator<Prescription> it = liste.iterator(); it
  216. .hasNext();) {
  217. Prescription courant = it.next();
  218. JLabel label = new JLabel();
  219. label.setText("<html><p style='font-size:14px'>"
  220. + courant.afficherPrescription()
  221. + "</p></html>");
  222. panneau.add(label);
  223. }
  224. nouvelle.add(panneau);
  225. nouvelle.setSize(400, nbPresc * 100);
  226. nouvelle.setVisible(true);
  227. }
  228.  
  229. }
  230. }
  231. }
  232.  
  233. public class BoutonPresc2Listener implements ActionListener {
  234. public void actionPerformed(ActionEvent arg0) {
  235. Object[] fields = { "Numéro d'assurance maladie", field1,
  236. "Nom du médicament", field2 };
  237. int option = JOptionPane.showConfirmDialog(null, fields,
  238. "Prescription", JOptionPane.OK_CANCEL_OPTION);
  239. String NAM = field1.getText();
  240. String medicament = field2.getText();
  241. if (option == JOptionPane.OK_OPTION) {
  242. if (pharma.servirPrescription(NAM, medicament)) {
  243. JOptionPane.showMessageDialog(null, "Prescription servie!",
  244. "Prescription", JOptionPane.INFORMATION_MESSAGE);
  245. } else {
  246. JOptionPane.showMessageDialog(null,
  247. "Il n'est pas possible de servir la prescription",
  248. "Prescription", JOptionPane.INFORMATION_MESSAGE);
  249. }
  250.  
  251. } else if (option == JOptionPane.CANCEL_OPTION
  252. || option == JOptionPane.CLOSED_OPTION) {
  253.  
  254. }
  255. }
  256. }
  257.  
  258. public class BoutonPresc3Listener implements ActionListener {
  259. public void actionPerformed(ActionEvent arg0) {
  260. Object[] fields = { "Numéro d'assurance maladie", field1,
  261. "Nom du médicament", field2, "Dose", field3,
  262. "Nombre de renouvellements", field4 };
  263. int option = JOptionPane.showConfirmDialog(null, fields,
  264. "Prescription", JOptionPane.OK_CANCEL_OPTION);
  265. String NAM = field1.getText();
  266. String medicament = field2.getText();
  267. double dose = Double.parseDouble(field3.getText());
  268. int renouv = Integer.parseInt(field4.getText());
  269. if (option == JOptionPane.OK_OPTION) {
  270. if (pharma.creerPrescription(NAM, medicament, dose, renouv)) {
  271. JOptionPane.showMessageDialog(null, "Prescription créée!",
  272. "Prescription", JOptionPane.INFORMATION_MESSAGE);
  273. } else {
  274. JOptionPane.showMessageDialog(null,
  275. "Il n'est pas possible de créer la prescription",
  276. "Prescription", JOptionPane.INFORMATION_MESSAGE);
  277. }
  278. } else if (option == JOptionPane.CANCEL_OPTION
  279. || option == JOptionPane.CLOSED_OPTION) {
  280.  
  281. }
  282. }
  283. }
  284.  
  285. public class BoutonMedic1Listener implements ActionListener {
  286. public void actionPerformed(ActionEvent arg0) {
  287. JFrame nouvelle = new JFrame("Médicaments");
  288. int nbMedic = pharma.getLesMedicaments().size();
  289. JPanel panneau = new JPanel();
  290. panneau.setLayout(new GridLayout(nbMedic, 1));
  291. panneau.setBackground(Color.white);
  292. for (Iterator<Medicament> it = pharma.getLesMedicaments()
  293. .iterator(); it.hasNext();) {
  294. Medicament courant = it.next();
  295. JLabel label = new JLabel();
  296. label.setText("<html><p style='font-size:14px'>"
  297. + courant.getNomMolecule() + " "
  298. + courant.getNomMarque() + "</p></html>");
  299. panneau.add(label);
  300. }
  301. nouvelle.add(panneau);
  302. nouvelle.setSize(400, nbMedic * 100);
  303. nouvelle.setVisible(true);
  304.  
  305. }
  306. }
  307.  
  308. public class BoutonMedic2Listener implements ActionListener {
  309. public void actionPerformed(ActionEvent arg0) {
  310. Object[] fields = { "Nom de la molécule ou du médicament no 1",
  311. field1, "Nom de la molécule ou du médicament no 2", field2 };
  312. int option = JOptionPane.showConfirmDialog(null, fields,
  313. "Interactions", JOptionPane.OK_CANCEL_OPTION);
  314. String medicament1 = field1.getText();
  315. String medicament2 = field2.getText();
  316. if (option == JOptionPane.OK_OPTION) {
  317. if (pharma.trouverInteraction(medicament1, medicament2)) {
  318. JOptionPane.showMessageDialog(null,
  319. "Interaction trouvée! Faites attention!",
  320. "Interactions", JOptionPane.INFORMATION_MESSAGE);
  321. } else {
  322. JOptionPane.showMessageDialog(null,
  323. "Il n'est pas possible de créer la prescription",
  324. "Prescription", JOptionPane.INFORMATION_MESSAGE);
  325. }
  326. } else if (option == JOptionPane.CANCEL_OPTION
  327. || option == JOptionPane.CLOSED_OPTION) {
  328.  
  329. } else {
  330. JOptionPane.showMessageDialog(null,
  331. "Aucune interaction trouvée!", "Interactions",
  332. JOptionPane.INFORMATION_MESSAGE);
  333. }
  334. }
  335. }
  336.  
  337. private void quitter() {
  338. int confirm = JOptionPane.showOptionDialog(null,
  339. "Voulez-vous vraiment vous quitter?",
  340. "Confirmation de fermeture", JOptionPane.YES_NO_CANCEL_OPTION,
  341. JOptionPane.QUESTION_MESSAGE, null, null, null);
  342. if (confirm == JOptionPane.YES_OPTION) {
  343. System.exit(0);
  344. } else {
  345.  
  346. }
  347. }
  348.  
  349. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement