Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package projetgarage;
- import Options.*;
- import Options.Options;
- import Options.VitreElectrique;
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.ComponentOrientation;
- import java.awt.Dimension;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.ArrayList;
- import javax.swing.ButtonGroup;
- import javax.swing.JButton;
- import javax.swing.JCheckBox;
- import javax.swing.JComboBox;
- import javax.swing.JDialog;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JRadioButton;
- import javax.swing.JTextField;
- import javax.swing.border.EmptyBorder;
- /**
- *
- * @author Formation
- */
- public class FenetreAddVoiture extends JDialog {
- double prixTotal;
- double prixOptionCalc = 0.0;
- double prixOption = 0.0;
- String marque;
- String typeMoteur;
- String cylindres;
- double prixMoteur;
- double prixCarcasse;
- String optionSelectionnees = " Option(s) choisie(s) : ";
- String tfPrixVoitureContent;
- String tfPrixMoteurContent;
- static ArrayList<String> nom = new ArrayList<>();
- BorderLayout experimentLayout;
- //*************************Declaration du Jpanel 1****************************************//
- JPanel panel1 = new JPanel();
- JComboBox marqueVoiture = new JComboBox(nom.toArray());
- JTextField prix = new JTextField(7);
- JLabel lbPrix = new JLabel("Prix : ");
- JButton btnAddCar = new JButton("Create Car");
- //*************************Declaration du Jpanel 2****************************************//
- JPanel panel2 = new JPanel();
- JLabel options = new JLabel("OPTIONS");
- JCheckBox gps = new JCheckBox("GPS");
- JCheckBox vitresElectriques = new JCheckBox("Vitres Electriques");
- JCheckBox siegeChauffant = new JCheckBox("Siège Chauffant");
- JCheckBox barreDeToit = new JCheckBox("Barre de toit");
- JCheckBox climatisation = new JCheckBox("Climatisation");
- JButton estimPrix = new JButton("Calc. Prix");
- //*************************Declaration du Jpanel 3****************************************//
- JPanel panel3 = new JPanel();
- JRadioButton essence = new JRadioButton("ESSENCE");
- JRadioButton diesel = new JRadioButton("DIESEL");
- JRadioButton hybride = new JRadioButton("HYBRIDE");
- JRadioButton electrique = new JRadioButton("ELECTRIQUE");
- ButtonGroup btngtypeMoteur = new ButtonGroup();
- JLabel lbPrixMoteur = new JLabel("prix");
- JTextField tfPrixMoteur = new JTextField(7);
- JLabel lbCylindre = new JLabel("Cylindres");
- JTextField tfCylindre = new JTextField(7);
- //**********************************classe de la fenetre AddVoiture
- public FenetreAddVoiture(JFrame parent, Garage garage) {
- super(parent);
- //**** ArrayList de la comboBox des nom de voitures***************//
- nom.add("Laguna");
- nom.add("208 Gti");
- nom.add("DS3");
- marqueVoiture = new JComboBox(nom.toArray());
- //*******************Parametres de la fenetre******************//
- this.setSize(new Dimension(400, 520));
- this.setBackground(Color.yellow);
- this.setDefaultLookAndFeelDecorated(true);
- this.setTitle("Add car");
- this.setLocationRelativeTo(this.getParent());
- panel1.setPreferredSize(new Dimension(190, 20));
- panel1.setBackground(Color.RED);
- //**********************Action quand on appuis sur "add car"***********************//
- btnAddCar.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- //// Gestion des données insérées dans le Panel 1 ///////
- //*******************recupère ce qu'il y a dans la ComboBox************//
- marque = (String) marqueVoiture.getSelectedItem();
- tfPrixVoitureContent=prix.getText();
- ////Gestion des données du Panel 3/////
- //*****************recupère le type de moteur dans les radiopoints*********//
- if (essence.isSelected()) {
- typeMoteur = "ESSENCE";
- } else if (diesel.isSelected()) {
- typeMoteur = "DIESEL";
- } else if (hybride.isSelected()) {
- typeMoteur = "HYBRIDE";
- } else if (electrique.isSelected()) {
- typeMoteur = "ELECTRIQUE";
- }
- tfPrixMoteurContent=prix.getText();
- cylindres=tfCylindre.getText();
- //Gestion des données du Panel 2//
- //**************calcul le prix des options et afficher une string avec les options utilisées*********//
- if (gps.isSelected()) {
- Options optgps = new GPS();
- prixOptionCalc += optgps.getPrix();
- optionSelectionnees += "-" + gps.getText() + " ";
- }
- if (vitresElectriques.isSelected()) {
- Options optVE = new VitreElectrique();
- prixOptionCalc += optVE.getPrix();
- optionSelectionnees += "-" + vitresElectriques.getText() + " ";
- }
- if (siegeChauffant.isSelected()) {
- Options optSC = new SiegeChauffant();
- prixOptionCalc += optSC.getPrix();
- optionSelectionnees += "-" + siegeChauffant.getText() + " ";
- }
- if (barreDeToit.isSelected()) {
- Options optBT = new BarreDeToit();
- prixOptionCalc += optBT.getPrix();
- optionSelectionnees += "-" + barreDeToit.getText() + " ";
- }
- if (climatisation.isSelected()) {
- Options optClim = new Climatisation();
- prixOptionCalc += optClim.getPrix();
- optionSelectionnees += "-" + climatisation.getText() + " ";
- }
- prixOption = prixOptionCalc;
- prixOptionCalc = 0.0;
- prixMoteur = Double.parseDouble(tfPrixMoteur.getText());
- prixCarcasse = Double.parseDouble(prix.getText());
- //*******affiche dans la console le type de moteur , le nom, et le prix des option du véhicule créé*************//
- System.out.println(typeMoteur +" "+ cylindres +" c");
- System.out.println(marque);
- System.out.println(optionSelectionnees + "pour " + prixOption + "€");
- System.out.println("Le moteur coutera "+prixMoteur+" €");
- System.out.println("La voiture seule coutera "+prixCarcasse+" €");
- System.out.println("Pour la maudite somme de "+(prixOption+prixMoteur+prixCarcasse)+ " €");
- System.out.println("\n\n\nVoiture Ajoutée");
- dispose();
- }
- });
- //***** parametre et ajoute les items au panel 1***//
- panel1.add(lbPrix);
- panel1.add(prix);
- panel1.add(marqueVoiture);
- panel1.add(btnAddCar);
- //***** parametre et ajoute les items au panel 2***//
- panel2.setPreferredSize(new Dimension(200, 10));
- panel2.setBackground(Color.ORANGE);
- panel2.add(options);
- panel2.add(gps);
- panel2.add(vitresElectriques);
- panel2.add(siegeChauffant);
- panel2.add(barreDeToit);
- panel2.add(climatisation);
- //***** paramètre et ajoute les items au panel 3***//
- panel3.setPreferredSize(new Dimension(150, 220));
- panel3.setBackground(Color.YELLOW);
- btngtypeMoteur.add(essence);
- btngtypeMoteur.add(diesel);
- btngtypeMoteur.add(hybride);
- btngtypeMoteur.add(electrique);
- panel3.add(essence);
- panel3.add(diesel);
- panel3.add(hybride);
- panel3.add(electrique);
- essence.setSelected(true);
- panel3.add(lbPrixMoteur);
- panel3.add(tfPrixMoteur);
- panel3.add(lbCylindre);
- panel3.add(tfCylindre);
- //**ajoute les panels à la fenètre**//
- this.add(panel1, BorderLayout.LINE_START);
- this.add(panel2, BorderLayout.LINE_END);
- this.add(panel3, BorderLayout.PAGE_END);
- this.setVisible(true);
- // JOptionPane.showMessageDialog(null, this);
- }
- }
Add Comment
Please, Sign In to add comment