Advertisement
Hello-Sweety

Untitled

Feb 15th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.86 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package projetgarage;
  7.  
  8. import Options.*;
  9. import Options.Options;
  10. import Options.VitreElectrique;
  11. import java.awt.BorderLayout;
  12. import java.awt.Color;
  13. import java.awt.ComponentOrientation;
  14. import java.awt.Dimension;
  15. import java.awt.GridBagConstraints;
  16. import java.awt.GridBagLayout;
  17. import java.awt.GridLayout;
  18. import java.awt.event.ActionEvent;
  19. import java.awt.event.ActionListener;
  20. import java.util.ArrayList;
  21. import javax.swing.ButtonGroup;
  22. import javax.swing.JButton;
  23. import javax.swing.JCheckBox;
  24. import javax.swing.JComboBox;
  25. import javax.swing.JDialog;
  26. import javax.swing.JFrame;
  27. import javax.swing.JLabel;
  28. import javax.swing.JOptionPane;
  29. import javax.swing.JPanel;
  30. import javax.swing.JRadioButton;
  31. import javax.swing.JTextField;
  32. import javax.swing.border.EmptyBorder;
  33.  
  34. /**
  35.  *
  36.  * @author Formation
  37.  */
  38. public class FenetreAddVoiture extends JDialog {
  39.     double prixTotal;
  40.     double prixOptionCalc = 0.0;
  41.     double prixOption = 0.0;
  42.     String marque;
  43.     String typeMoteur;
  44.     String cylindres;
  45.     double prixMoteur;
  46.     double prixCarcasse;
  47.     String optionSelectionnees = " Option(s) choisie(s) : ";
  48.     String tfPrixVoitureContent;
  49.     String tfPrixMoteurContent;
  50.     static ArrayList<String> nom = new ArrayList<>();
  51.     BorderLayout experimentLayout;
  52.  
  53.     //*************************Declaration du Jpanel 1****************************************//
  54.     JPanel panel1 = new JPanel();
  55.     JComboBox marqueVoiture = new JComboBox(nom.toArray());
  56.     JTextField prix = new JTextField(7);
  57.     JLabel lbPrix = new JLabel("Prix : ");
  58.     JButton btnAddCar = new JButton("Create Car");
  59.     //*************************Declaration du Jpanel 2****************************************//
  60.     JPanel panel2 = new JPanel();
  61.     JLabel options = new JLabel("OPTIONS");
  62.  
  63.     JCheckBox gps = new JCheckBox("GPS");
  64.     JCheckBox vitresElectriques = new JCheckBox("Vitres Electriques");
  65.     JCheckBox siegeChauffant = new JCheckBox("Siège Chauffant");
  66.     JCheckBox barreDeToit = new JCheckBox("Barre de toit");
  67.     JCheckBox climatisation = new JCheckBox("Climatisation");
  68.  
  69.     JButton estimPrix = new JButton("Calc. Prix");
  70.  
  71.     //*************************Declaration du Jpanel 3****************************************//  
  72.     JPanel panel3 = new JPanel();
  73.     JRadioButton essence = new JRadioButton("ESSENCE");
  74.     JRadioButton diesel = new JRadioButton("DIESEL");
  75.     JRadioButton hybride = new JRadioButton("HYBRIDE");
  76.     JRadioButton electrique = new JRadioButton("ELECTRIQUE");
  77.     ButtonGroup btngtypeMoteur = new ButtonGroup();
  78.  
  79.     JLabel lbPrixMoteur = new JLabel("prix");
  80.     JTextField tfPrixMoteur = new JTextField(7);
  81.  
  82.     JLabel lbCylindre = new JLabel("Cylindres");
  83.     JTextField tfCylindre = new JTextField(7);
  84.     //**********************************classe de la fenetre AddVoiture      
  85.  
  86.     public FenetreAddVoiture(JFrame parent, Garage garage) {
  87.  
  88.         super(parent);
  89. //**** ArrayList de la comboBox des nom de voitures***************//
  90.         nom.add("Laguna");
  91.         nom.add("208 Gti");
  92.         nom.add("DS3");
  93.         marqueVoiture = new JComboBox(nom.toArray());
  94. //*******************Parametres de la fenetre******************//        
  95.  
  96.         this.setSize(new Dimension(400, 520));
  97.  
  98.         this.setBackground(Color.yellow);
  99.  
  100.         this.setDefaultLookAndFeelDecorated(true);
  101.  
  102.         this.setTitle("Add car");
  103.  
  104.         this.setLocationRelativeTo(this.getParent());
  105.  
  106.         panel1.setPreferredSize(new Dimension(190, 20));
  107.         panel1.setBackground(Color.RED);
  108.  
  109. //**********************Action quand on appuis sur "add car"***********************//
  110.         btnAddCar.addActionListener(new ActionListener() {
  111.             @Override
  112.             public void actionPerformed(ActionEvent e) {
  113. //// Gestion des données insérées dans le Panel 1 ///////
  114.                 //*******************recupère ce qu'il y a dans la ComboBox************//    
  115.                 marque = (String) marqueVoiture.getSelectedItem();
  116.                
  117.                 tfPrixVoitureContent=prix.getText();
  118.                
  119. ////Gestion des données du Panel 3/////
  120.                 //*****************recupère le type de moteur dans les radiopoints*********//    
  121.                 if (essence.isSelected()) {
  122.                     typeMoteur = "ESSENCE";
  123.                 } else if (diesel.isSelected()) {
  124.                     typeMoteur = "DIESEL";
  125.                 } else if (hybride.isSelected()) {
  126.                     typeMoteur = "HYBRIDE";
  127.                 } else if (electrique.isSelected()) {
  128.                     typeMoteur = "ELECTRIQUE";
  129.                 }
  130.                
  131.                 tfPrixMoteurContent=prix.getText();
  132.                
  133.                
  134.                 cylindres=tfCylindre.getText();
  135.                
  136. //Gestion des données du Panel 2//
  137.                 //**************calcul le prix des options et afficher une string avec les options utilisées*********//    
  138.                 if (gps.isSelected()) {
  139.  
  140.                     Options optgps = new GPS();
  141.                     prixOptionCalc += optgps.getPrix();
  142.  
  143.                     optionSelectionnees += "-" + gps.getText() + "   ";
  144.  
  145.                 }
  146.  
  147.                 if (vitresElectriques.isSelected()) {
  148.  
  149.                     Options optVE = new VitreElectrique();
  150.                     prixOptionCalc += optVE.getPrix();
  151.  
  152.                     optionSelectionnees += "-" + vitresElectriques.getText() + "   ";
  153.  
  154.                 }
  155.  
  156.                 if (siegeChauffant.isSelected()) {
  157.  
  158.                     Options optSC = new SiegeChauffant();
  159.                     prixOptionCalc += optSC.getPrix();
  160.  
  161.                     optionSelectionnees += "-" + siegeChauffant.getText() + "   ";
  162.  
  163.                 }
  164.  
  165.                 if (barreDeToit.isSelected()) {
  166.  
  167.                     Options optBT = new BarreDeToit();
  168.                     prixOptionCalc += optBT.getPrix();
  169.  
  170.                     optionSelectionnees += "-" + barreDeToit.getText() + "   ";
  171.  
  172.                 }
  173.  
  174.                 if (climatisation.isSelected()) {
  175.  
  176.                     Options optClim = new Climatisation();
  177.                     prixOptionCalc += optClim.getPrix();
  178.  
  179.                     optionSelectionnees += "-" + climatisation.getText() + "   ";
  180.  
  181.                 }
  182.                 prixOption = prixOptionCalc;
  183.                 prixOptionCalc = 0.0;
  184.  
  185.                 prixMoteur = Double.parseDouble(tfPrixMoteur.getText());
  186.                 prixCarcasse = Double.parseDouble(prix.getText());
  187.                 //*******affiche dans la console le type de moteur , le nom, et le prix des option du véhicule créé*************//  
  188.                 System.out.println(typeMoteur +" "+ cylindres +" c");
  189.                 System.out.println(marque);
  190.                 System.out.println(optionSelectionnees + "pour " + prixOption + "€");
  191.                 System.out.println("Le moteur coutera "+prixMoteur+" €");
  192.                 System.out.println("La voiture seule coutera "+prixCarcasse+" €");
  193.                 System.out.println("Pour la maudite somme de "+(prixOption+prixMoteur+prixCarcasse)+ " €");
  194.                
  195.                 System.out.println("\n\n\nVoiture Ajoutée");  
  196.                 dispose();
  197.                
  198.             }
  199.         });
  200.  
  201.         //***** parametre et ajoute les items au panel 1***//
  202.         panel1.add(lbPrix);
  203.         panel1.add(prix);
  204.         panel1.add(marqueVoiture);
  205.         panel1.add(btnAddCar);
  206.  
  207.         //***** parametre et ajoute les items au panel 2***//
  208.         panel2.setPreferredSize(new Dimension(200, 10));
  209.         panel2.setBackground(Color.ORANGE);
  210.  
  211.         panel2.add(options);
  212.         panel2.add(gps);
  213.         panel2.add(vitresElectriques);
  214.         panel2.add(siegeChauffant);
  215.         panel2.add(barreDeToit);
  216.         panel2.add(climatisation);
  217.  
  218.         //***** paramètre et ajoute les items au panel 3***//
  219.         panel3.setPreferredSize(new Dimension(150, 220));
  220.         panel3.setBackground(Color.YELLOW);
  221.  
  222.         btngtypeMoteur.add(essence);
  223.         btngtypeMoteur.add(diesel);
  224.         btngtypeMoteur.add(hybride);
  225.         btngtypeMoteur.add(electrique);
  226.  
  227.         panel3.add(essence);
  228.         panel3.add(diesel);
  229.         panel3.add(hybride);
  230.         panel3.add(electrique);
  231.         essence.setSelected(true);
  232.  
  233.         panel3.add(lbPrixMoteur);
  234.         panel3.add(tfPrixMoteur);
  235.         panel3.add(lbCylindre);
  236.         panel3.add(tfCylindre);
  237.  
  238.         //**ajoute les panels à la fenètre**//
  239.         this.add(panel1, BorderLayout.LINE_START);
  240.         this.add(panel2, BorderLayout.LINE_END);
  241.         this.add(panel3, BorderLayout.PAGE_END);
  242.  
  243.         this.setVisible(true);
  244.         // JOptionPane.showMessageDialog(null, this);
  245.     }
  246.  
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement