Package GUILayer

Source Code of GUILayer.GUI

package GUILayer;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;

import javax.swing.JButton;
import javax.swing.JLabel;

import ControlLayer.ControlCustomer;
import ControlLayer.ControlProduct;
import ModelLayer.Customer;
import ModelLayer.Product;


import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import ControlLayer.*;
import ModelLayer.*;

public class GUI extends JFrame {

  private JPanel contentPane;
  private JTextField textField;
  private JTextField textField_1;
  private JTextField textField_2;
  private JTextField textField_3;
  private JTextField textField_4;
  private JTextField textField_5;
  private JTextField textField_6;
  private JTextField textField_7;
  private JTextField textField_8;
  private JTextField textField_9;
  private JTextField textField_10;
  private JTextField textField_11;
  private JTextField textField_12;
  private JTextField textField_13;
  private JTextField textField_15;
  private JTextField textField_16;
  private JTextField textField_17;
  private JTextField textField_18;
  private JTextField textField_19;
  private JTextField textField_20;
  private JTextField textField_21;
  private JTextField textField_14;
  private JTextField textField_22;
  private JTextField textField_23;
  private JTextField textField_24;
  private JTextField textField_25;

  /**
   * Launch the application.
   */
  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
      public void run() {
        try {
          GUI frame = new GUI();
          frame.setVisible(true);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    });
  }

  /**
   * Create the frame.
   */
  public GUI() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 781, 470);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);
   
    JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    tabbedPane.setBounds(10, 11, 745, 410);
    contentPane.add(tabbedPane);
   
    JPanel panel = new JPanel();
    tabbedPane.addTab("Orders menu", null, panel, null);
    panel.setLayout(null);
   
    JPanel panel_1 = new JPanel();
    panel_1.setBounds(10, 11, 350, 360);
    panel.add(panel_1);
    panel_1.setLayout(null);
   
    JLabel label = new JLabel("");
    label.setBounds(153, 11, 46, 14);
    panel_1.add(label);
   
    JPanel panel_2 = new JPanel();
    panel_2.setLayout(null);
    panel_2.setBounds(380, 11, 350, 360);
    panel.add(panel_2);
   
    JLabel label_3 = new JLabel("");
    label_3.setBounds(153, 11, 46, 14);
    panel_2.add(label_3);
   
    JPanel panel_3 = new JPanel();
    tabbedPane.addTab("Customer menu", null, panel_3, null);
    panel_3.setLayout(null);
   
    JPanel panel_6 = new JPanel();
    panel_6.setBounds(10, 11, 720, 360);
    panel_3.add(panel_6);
    panel_6.setLayout(null);
   
    JLabel lblCreateCustomer = new JLabel("\r\nCUSTOMER");
    lblCreateCustomer.setBounds(338, 12, 97, 14);
    panel_6.add(lblCreateCustomer);
   
    JLabel label_1 = new JLabel("");
    label_1.setBounds(226, 12, 0, 0);
    panel_6.add(label_1);
   
    JLabel lblCpr = new JLabel("CPR");
    lblCpr.setBounds(10, 50, 46, 14);
    panel_6.add(lblCpr);
   
    JLabel lblFirstName = new JLabel("First name");
    lblFirstName.setBounds(10, 91, 70, 14);
    panel_6.add(lblFirstName);
   
    JLabel lblLastName = new JLabel("Last name");
    lblLastName.setBounds(10, 130, 70, 14);
    panel_6.add(lblLastName);
   
    JLabel lblNewLabel = new JLabel("Address");
    lblNewLabel.setBounds(10, 172, 56, 14);
    panel_6.add(lblNewLabel);
   
    JLabel lblZipcode = new JLabel("ZipCode");
    lblZipcode.setBounds(10, 208, 46, 14);
    panel_6.add(lblZipcode);
   
    JButton btnCreateCustomer = new JButton("Update Customer");
    btnCreateCustomer.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent eve) {
        updateCustomer(eve);
      }
    });
    btnCreateCustomer.setBounds(418, 326, 132, 23);
    panel_6.add(btnCreateCustomer);
   
    JButton btnFind = new JButton("Search");
    btnFind.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent eve) {
       
      searchCustomer(eve);
      }
    });
    btnFind.setBounds(268, 46, 72, 23);
    panel_6.add(btnFind);
   
    JButton button = new JButton("Delete Customer");
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent eve) {
        deleteCustomer(eve);
      }
    });
    button.setBounds(570, 326, 114, 23);
    panel_6.add(button);
   
    JLabel lblCity = new JLabel("City\r\n");
    lblCity.setBounds(10, 299, 46, 14);
    panel_6.add(lblCity);
   
    JButton button_1 = new JButton("Create Customer");
    button_1.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent eve) {
        try {
        CreateCustomer(eve);
        } catch (Exception e) {

          e.printStackTrace();
        }
       
      }
    });
    button_1.setBounds(285, 326, 114, 23);
    panel_6.add(button_1);
   
    textField = new JTextField();
    textField.setBounds(96, 47, 162, 20);
    panel_6.add(textField);
    textField.setColumns(10);
   
    textField_1 = new JTextField();
    textField_1.setColumns(10);
    textField_1.setBounds(96, 88, 162, 20);
    panel_6.add(textField_1);
   
    textField_2 = new JTextField();
    textField_2.setColumns(10);
    textField_2.setBounds(96, 127, 162, 20);
    panel_6.add(textField_2);
   
    textField_3 = new JTextField();
    textField_3.setColumns(10);
    textField_3.setBounds(96, 169, 162, 20);
    panel_6.add(textField_3);
   
    textField_4 = new JTextField();
    textField_4.setColumns(10);
    textField_4.setBounds(96, 205, 86, 20);
    panel_6.add(textField_4);
   
    textField_5 = new JTextField();
    textField_5.setEditable(false);
    textField_5.setColumns(10);
    textField_5.setBounds(96, 296, 162, 20);
    panel_6.add(textField_5);
   
    JLabel lblTelephonenumber = new JLabel("Telephone");
    lblTelephonenumber.setBounds(10, 251, 70, 14);
    panel_6.add(lblTelephonenumber);
   
    textField_6 = new JTextField();
    textField_6.setColumns(10);
    textField_6.setBounds(96, 248, 162, 20);
    panel_6.add(textField_6);
   
    JPanel panel_4 = new JPanel();
    tabbedPane.addTab("Product menu", null, panel_4, null);
    panel_4.setLayout(null);
   
    JPanel panel_7 = new JPanel();
    panel_7.setBounds(369, 5, 1, 1);
    panel_7.setLayout(null);
    panel_4.add(panel_7);
   
    JLabel label_2 = new JLabel("CREATE CUSTOMER");
    label_2.setBounds(321, 12, 97, 14);
    panel_7.add(label_2);
   
    JLabel label_4 = new JLabel("");
    label_4.setBounds(226, 12, 0, 0);
    panel_7.add(label_4);
   
    JLabel label_5 = new JLabel("CPR");
    label_5.setBounds(10, 50, 46, 14);
    panel_7.add(label_5);
   
    JLabel label_6 = new JLabel("First name");
    label_6.setBounds(10, 91, 70, 14);
    panel_7.add(label_6);
   
    JLabel label_7 = new JLabel("Last name");
    label_7.setBounds(10, 130, 70, 14);
    panel_7.add(label_7);
   
    JLabel label_8 = new JLabel("Address");
    label_8.setBounds(10, 172, 56, 14);
    panel_7.add(label_8);
   
    JLabel label_9 = new JLabel("ZipCode");
    label_9.setBounds(10, 208, 46, 14);
    panel_7.add(label_9);
   
    JButton button_2 = new JButton("Update Customer");
    button_2.setBounds(418, 326, 132, 23);
    panel_7.add(button_2);
   
    JButton button_3 = new JButton("Search");
    button_3.setBounds(268, 46, 72, 23);
    panel_7.add(button_3);
   
    JButton button_4 = new JButton("Delete Customer");
    button_4.setBounds(570, 326, 114, 23);
    panel_7.add(button_4);
   
    JLabel label_10 = new JLabel("City\r\n");
    label_10.setBounds(10, 299, 46, 14);
    panel_7.add(label_10);
   
    JButton button_5 = new JButton("Create Customer");
    button_5.setBounds(285, 326, 114, 23);
    panel_7.add(button_5);
   
    textField_7 = new JTextField();
    textField_7.setColumns(10);
    textField_7.setBounds(96, 47, 162, 20);
    panel_7.add(textField_7);
   
    textField_8 = new JTextField();
    textField_8.setColumns(10);
    textField_8.setBounds(96, 88, 162, 20);
    panel_7.add(textField_8);
   
    textField_9 = new JTextField();
    textField_9.setColumns(10);
    textField_9.setBounds(96, 127, 162, 20);
    panel_7.add(textField_9);
   
    textField_10 = new JTextField();
    textField_10.setColumns(10);
    textField_10.setBounds(96, 169, 162, 20);
    panel_7.add(textField_10);
   
    textField_11 = new JTextField();
    textField_11.setColumns(10);
    textField_11.setBounds(96, 205, 86, 20);
    panel_7.add(textField_11);
   
    textField_12 = new JTextField();
    textField_12.setEditable(false);
    textField_12.setColumns(10);
    textField_12.setBounds(96, 296, 162, 20);
    panel_7.add(textField_12);
   
    JLabel label_11 = new JLabel("Telephone");
    label_11.setBounds(10, 251, 70, 14);
    panel_7.add(label_11);
   
    textField_13 = new JTextField();
    textField_13.setColumns(10);
    textField_13.setBounds(96, 248, 162, 20);
    panel_7.add(textField_13);
   
    JPanel panel_8 = new JPanel();
    panel_8.setLayout(null);
    panel_8.setBounds(10, 5, 720, 360);
    panel_4.add(panel_8);
   
    JLabel lblProduct = new JLabel("PRODUCT");
    lblProduct.setBounds(337, 12, 97, 14);
    panel_8.add(lblProduct);
   
    JLabel label_13 = new JLabel("");
    label_13.setBounds(226, 12, 0, 0);
    panel_8.add(label_13);
   
    JLabel lblName = new JLabel("Name");
    lblName.setBounds(10, 91, 70, 14);
    panel_8.add(lblName);
   
    JLabel lblPurchasePrice = new JLabel("purchase price");
    lblPurchasePrice.setBounds(10, 130, 70, 14);
    panel_8.add(lblPurchasePrice);
   
    JLabel lblSalePrice = new JLabel("sale price");
    lblSalePrice.setBounds(10, 172, 56, 14);
    panel_8.add(lblSalePrice);
   
    JLabel lblRentPrice = new JLabel("rent price");
    lblRentPrice.setBounds(10, 208, 46, 14);
    panel_8.add(lblRentPrice);
   
    JButton btnUpdateProduct = new JButton("Update Product");
    btnUpdateProduct.setBounds(418, 326, 132, 23);
    panel_8.add(btnUpdateProduct);
   
    JButton button_7 = new JButton("Search");
    button_7.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        searchProduct(e);
      }
    });
    button_7.setBounds(278, 87, 72, 23);
    panel_8.add(button_7);
   
    JButton btnDeleteProduct = new JButton("Delete Product");
    btnDeleteProduct.setBounds(570, 326, 114, 23);
    panel_8.add(btnDeleteProduct);
   
    JLabel lblMinstock = new JLabel("minStock");
    lblMinstock.setBounds(10, 299, 46, 14);
    panel_8.add(lblMinstock);
   
    JButton btnCreateProduct = new JButton("Create Product");
    btnCreateProduct.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        createProduct(e);
      }
    });
    btnCreateProduct.setBounds(285, 326, 114, 23);
    panel_8.add(btnCreateProduct);
   
    textField_15 = new JTextField();
    textField_15.setColumns(10);
    textField_15.setBounds(108, 88, 150, 20);
    panel_8.add(textField_15);
   
    textField_16 = new JTextField();
    textField_16.setColumns(10);
    textField_16.setBounds(108, 127, 86, 20);
    panel_8.add(textField_16);
   
    textField_17 = new JTextField();
    textField_17.setColumns(10);
    textField_17.setBounds(108, 169, 86, 20);
    panel_8.add(textField_17);
   
    textField_18 = new JTextField();
    textField_18.setColumns(10);
    textField_18.setBounds(108, 205, 86, 20);
    panel_8.add(textField_18);
   
    textField_19 = new JTextField();
    textField_19.setColumns(10);
    textField_19.setBounds(108, 296, 86, 20);
    panel_8.add(textField_19);
   
    JLabel lblCountryoforigin = new JLabel("countryOfOrigin");
    lblCountryoforigin.setBounds(10, 251, 97, 14);
    panel_8.add(lblCountryoforigin);
   
    textField_20 = new JTextField();
    textField_20.setColumns(10);
    textField_20.setBounds(108, 248, 150, 20);
    panel_8.add(textField_20);
   
    JLabel lblSupplier = new JLabel("supplier");
    lblSupplier.setBounds(258, 299, 46, 14);
    panel_8.add(lblSupplier);
   
    textField_21 = new JTextField();
    textField_21.setColumns(10);
    textField_21.setBounds(313, 296, 97, 20);
    panel_8.add(textField_21);
   
    JPanel panel_5 = new JPanel();
    tabbedPane.addTab("Supplier menu", null, panel_5, null);
    panel_5.setLayout(null);
   
    textField_14 = new JTextField();
    textField_14.setBounds(152, 49, 151, 20);
    panel_5.add(textField_14);
    textField_14.setColumns(10);
   
    JLabel lblNewLabel_1 = new JLabel("Name:");
    lblNewLabel_1.setBounds(10, 49, 66, 14);
    panel_5.add(lblNewLabel_1);
   
    textField_22 = new JTextField();
    textField_22.setColumns(10);
    textField_22.setBounds(152, 80, 151, 20);
   
    panel_5.add(textField_22);
   
    textField_23 = new JTextField();
    textField_23.setColumns(10);
    textField_23.setBounds(152, 111, 151, 20);
    panel_5.add(textField_23);
   
    textField_24 = new JTextField();
    textField_24.setColumns(10);
    textField_24.setBounds(152, 142, 151, 20);
    panel_5.add(textField_24);
   
    textField_25 = new JTextField();
    textField_25.setColumns(10);
    textField_25.setBounds(152, 173, 151, 20);
    panel_5.add(textField_25);
   
    JLabel lblAddress = new JLabel("Address:");
    lblAddress.setBounds(10, 80, 66, 14);
    panel_5.add(lblAddress);
   
    JLabel lblCountry = new JLabel("Country:");
    lblCountry.setBounds(10, 111, 66, 14);
    panel_5.add(lblCountry);
   
    JLabel lblPhoneNumber = new JLabel("Phone Number:");
    lblPhoneNumber.setBounds(10, 142, 98, 14);
    panel_5.add(lblPhoneNumber);
   
    JLabel lblEmail = new JLabel("E-mail:");
    lblEmail.setBounds(10, 173, 66, 14);
    panel_5.add(lblEmail);
   
    JLabel lblSuplier = new JLabel("SUPPLIER");
    lblSuplier.setBounds(323, 11, 66, 14);
    panel_5.add(lblSuplier);
   
    JButton btnNewButton = new JButton("Create Supplier");
    btnNewButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        ControlSupplier supplierCtrl = new ControlSupplier();
        String name = textField_14.getText();
        String address = textField_22.getText();
        String country = textField_23.getText();
        String phoneNumber = textField_24.getText();
        String email = textField_25.getText();
        supplierCtrl.insertNew(name, address, country, phoneNumber, email);
       
        textField_14.setText("");
        textField_22.setText("");
        textField_23.setText("");
        textField_24.setText("");
        textField_25.setText("");
      }
    });
    btnNewButton.setBounds(10, 265, 129, 23);
    panel_5.add(btnNewButton);
   
    JButton btnNewButton_1 = new JButton("Update Supplier");
    btnNewButton_1.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        ControlSupplier supplierCtrl = new ControlSupplier();
        String name = textField_14.getText();
        String address = textField_22.getText();
        String country = textField_23.getText();
        String phoneNumber = textField_24.getText();
        String email = textField_25.getText();
        supplierCtrl.updateSupplier(name, address, country, phoneNumber, email);
        textField_14.setText("");
        textField_22.setText("");
        textField_23.setText("");
        textField_24.setText("");
        textField_25.setText("");
      }
    });
    btnNewButton_1.setBounds(149, 265, 125, 23);
    panel_5.add(btnNewButton_1);
   
    JButton btnNewButton_2 = new JButton("Delete Supplier");
    btnNewButton_2.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        ControlSupplier supplierCtrl = new ControlSupplier();
        String name = textField_14.getText();
       
        supplierCtrl.deleteSupplier(name);
        textField_14.setText("");
      }
    });
    btnNewButton_2.setBounds(284, 265, 121, 23);
    panel_5.add(btnNewButton_2);
   
    JButton btnNewButton_3 = new JButton("Search");
    btnNewButton_3.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        ControlSupplier supplierCtrl = new ControlSupplier();
        Supplier supplier = new Supplier ();
       
        String name = textField_14.getText();
        supplier = supplierCtrl.searchByName(name);
       
        textField_14.setText(supplier.getName());
        textField_22.setText(supplier.getAddress());
        textField_23.setText(supplier.getCountry());
        textField_24.setText(supplier.getPhoneNumber());
        textField_25.setText(supplier.getEmail());
        textField_22.setHorizontalAlignment(JTextField.LEFT);
       
       
      }
    });
    btnNewButton_3.setBounds(338, 48, 89, 23);
    panel_5.add(btnNewButton_3);
  }
 
 
 
 
  public void CreateCustomer(ActionEvent eve) throws Exception{
    ControlCustomer ctrCust=new ControlCustomer();
    String cpr=textField.getText();
    String fname = textField_1.getText();
        String lname = textField_2.getText();
    String address=textField_3.getText();
    int zipCode= Integer.valueOf(textField_4.getText());
    String phoneNumber=textField_6.getText();
    ctrCust.insertCustomer(cpr, fname,lname, address,zipCode, phoneNumber);
    textField_1.setText("");
    textField_2.setText("");
    textField_3.setText("");
    textField_4.setText("");
    textField_6.setText("");
  }
 
 
  public void searchCustomer(ActionEvent eve){
    ControlCustomer ctrCust=new ControlCustomer();
    String cpr=textField.getText();
    Customer cust=ctrCust.findCustomer(cpr);
    textField_1.setText(cust.getFirsTName());
    textField_2.setText(cust.getLastName());
    textField_3.setText(cust.getAddress());
    textField_4.setText(Integer.toString(cust.getCity().getZipCode()));
    textField_5.setText(cust.getCity().getCity());
    textField_6.setText(cust.getPhoneNumber());
   
  }
 
  public void updateCustomer(ActionEvent eve){
    ControlCustomer ctrCust=new ControlCustomer();
    String cpr=textField.getText();
    String firstName=textField_1.getText();
    String lastName=textField_2.getText();
    String address=textField_3.getText();
    int zipcode=Integer.valueOf(textField_4.getText());
    String phoneNumber=textField_6.getText();
    ctrCust.updateCustomer(cpr, firstName, lastName, address, zipcode, phoneNumber);
    textField_1.setText("");
    textField_2.setText("");
    textField_3.setText("");
    textField_4.setText("");
    textField_6.setText("");
  }
 
  public void deleteCustomer(ActionEvent eve){
    ControlCustomer ctrCust=new ControlCustomer();
    String cpr=textField.getText();
    ctrCust.deleteCustomer(cpr);
    textField.setText("");
    textField_1.setText("");
    textField_2.setText("");
    textField_3.setText("");
    textField_4.setText("");
    textField_6.setText("");
  }
 
  public void createProduct(ActionEvent e){
    ControlProduct ctrProd=new ControlProduct();
    //int id=Integer.valueOf(textField_14.getText());
    String name=textField_15.getText();
    double purchasePrice=Double.valueOf(textField_16.getText());
    double salePrice=Double.valueOf(textField_17.getText());
     double rentPrice=Double.valueOf(textField_18.getText());
     String countryOfOrigin=textField_20.getText();
     int minStock=Integer.valueOf(textField_19.getText());
     String suplier=textField_21.getText();
     ctrProd.createProduct(name, purchasePrice, salePrice, rentPrice, countryOfOrigin, minStock, suplier);
     //textField_14.setText("");
     textField_16.setText("");
     textField_17.setText("");
     textField_18.setText("");
        textField_19.setText("");
       textField_20.setText("");
       textField_21.setText("");
    
  }
 
  public void searchProduct(ActionEvent e){
    ControlProduct ctrProd=new ControlProduct();
    String name=textField_15.getText();
    Product prod= ctrProd.findProduct(name, false);
    textField_15.setText(prod.getName());
    textField_16.setText(String.valueOf(prod.getPurchasePrice()));
    textField_17.setText(String.valueOf(prod.getSalesPrice()));
    textField_18.setText(String.valueOf(prod.getRentPrice()));
    textField_19.setText(String.valueOf(prod.getMinStock()));
    textField_20.setText(prod.getCountryOfOrigin());
    textField_21.setText(prod.getSupplier().getName());
   
   
  }
}
 

       
        
            
   

TOP

Related Classes of GUILayer.GUI

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.