Advertisement
ruhul0

Gui

Apr 24th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 27.68 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.io.*;
  6.  
  7. /**
  8.  * Created by user on 30/03/17.
  9.  */
  10. public class Gui implements ActionListener{
  11.     JFrame loginFrame = new JFrame("Your Shop");
  12.  
  13.     JFrame dashboardFrame = new JFrame("Your Shop DashBoard");
  14.     JFrame modifyProduct = new JFrame("Modify Product");
  15.     JFrame newProduct = new JFrame("New Product");
  16.     JFrame delete = new JFrame("Delete Product");
  17.  
  18.     JFrame order = new JFrame("Order");
  19.  
  20.     JLabel userNameLabel = new JLabel("User Name:");
  21.     JLabel passwordLabel = new JLabel("Enter Password:");
  22.  
  23. //    JLabel productID = new JLabel("Product ID");
  24. //    JLabel productName = new JLabel("Product NAme");
  25. //    JLabel productPrice = new JLabel("Price");
  26. //    JLabel productQuantity = new JLabel("Quantity");
  27.  
  28.     JLabel productID = new JLabel("Product ID");
  29.     JLabel productName = new JLabel("Product NAme");
  30.     JLabel productPrice = new JLabel("Price");
  31.     JLabel productQuantity = new JLabel("Quantity");
  32.  
  33.     JLabel modproductID = new JLabel("Modify Product ID");
  34.     JLabel modproductName = new JLabel("Modify  NAme");
  35.     JLabel modproductPrice = new JLabel("Modify Price");
  36.     JLabel modproductQuantity = new JLabel("Modify Quantity");
  37.  
  38.     JTextField userNameTextField = new JTextField("admin");
  39.     JTextField passwordField = new JTextField("admin");
  40.  
  41.     JTextField searchTextField = new JTextField("");
  42.     JButton clear = new JButton("Clear");
  43.  
  44.  
  45.     JLabel showProductInfo = new JLabel();
  46.  
  47.     JLabel productInfo = new JLabel();
  48.  
  49.     JTextField orderQuantity = new JTextField();
  50.  
  51.     JLabel label = new JLabel();
  52.     //JTable table = new JTable();
  53.  
  54. //    JTextField productIDtext = new JTextField("");
  55. //    JTextField productNameText = new JTextField("");
  56. //    JTextField priceText = new JTextField("");
  57. //    JTextField quantitytext = new JTextField("");
  58. //
  59. //    JTextField productIDtext = new JTextField("");
  60. //    JTextField productNameText = new JTextField("");
  61. //    JTextField priceText = new JTextField("");
  62. //    JTextField quantitytext = new JTextField("");
  63.  
  64.     JTextField productIDtext = new JTextField("");
  65.     JTextField productNameText = new JTextField("");
  66.     JTextField priceText = new JTextField("");
  67.     JTextField quantitytext = new JTextField("");
  68.  
  69.  
  70.  
  71.     JButton signIn = new JButton("Sign In");
  72.     JButton searchButton = new JButton("Search");
  73.     JButton addOrder = new JButton("Add new Order");
  74.     JButton addProducts = new JButton("Add new Product");
  75.     JButton modifyProducts = new JButton("Modify Products");
  76.     JButton deleteProducts = new JButton("Delete Products");
  77.     JButton showProduct  = new JButton("Show Products");
  78.     JButton done = new JButton("Done");
  79.     JButton back = new JButton("Back");
  80.  
  81.     JLabel bg = new JLabel(new ImageIcon("bg.jpg"));
  82.  
  83.     //String column[]={"ID","Name","Price","Quantity"};
  84.     int i=0;
  85.     int j;
  86.     static boolean foundProduct=false;
  87.     double price;
  88.     int quantity;
  89.  
  90.     String filename = "product.txt";
  91.     FileWriter fw = new FileWriter(new File(filename),true);
  92.     BufferedReader br = new BufferedReader(new FileReader(filename));
  93.  
  94.  
  95.     public Gui() throws IOException {
  96.  
  97.  
  98.  
  99.         loginFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  100.         loginFrame.setSize(500, 700);
  101.         loginFrame.setLayout(null);
  102.         loginFrame.setVisible(true);
  103.  
  104.  
  105.         loginFrame.add(userNameLabel);
  106.         userNameLabel.setBounds(30,50,100,20);
  107.         userNameLabel.setVisible(true);
  108.  
  109.  
  110.         loginFrame.add(userNameTextField);
  111.         userNameTextField.setBounds(130,51,120,25);
  112.         userNameTextField.setVisible(true);
  113.  
  114.         loginFrame.add(passwordLabel);
  115.         passwordLabel.setBounds(30,90,100,10);
  116.         passwordLabel.setVisible(true);
  117.  
  118.  
  119.         loginFrame.add(passwordField);
  120.         passwordField.setBounds(130,91,120,25);
  121.         passwordField.setVisible(true);
  122.  
  123.  
  124.  
  125.  
  126.         loginFrame.add(signIn);
  127.         signIn.setBounds(130,140,100,30);
  128.         //passwordField.setActionCommand(String.valueOf(new Login()));
  129.         //passwordField.addActionListener(new Login());
  130.         signIn.addActionListener(new DashBoard());
  131.         loginFrame.add(bg);
  132.         backGround();
  133.  
  134.     }
  135. /*    void passwordCheck(){
  136.         if( (userNameTextField.getText().equals("admin") && passwordField.getText().equals("admin")))
  137.         {
  138.             new DashBoard();
  139.             loginFrame.dispose();
  140.         }
  141.         else
  142.         {
  143.             //JOptionPane.showMessageDialog(this,"incorrect login info");
  144.             new DashBoard();
  145.             System.out.println("wrong login info");
  146.         }
  147.  
  148.     }*/
  149. /*    public class Login extends Component implements ActionListener{
  150.  
  151.         @Override
  152.         public void actionPerformed(ActionEvent e) {
  153.  
  154.             {
  155.                 passwordCheck();
  156.                 signIn.addActionListener(new DashBoard());
  157.                 loginFrame.dispose();
  158.             }
  159.             else
  160.             {
  161.                 //JOptionPane.showMessageDialog(this,"incorrect login info");
  162.                 //System.out.println("wrong login info");
  163.             }
  164.         }
  165.     }*/
  166.  
  167.     public static void main(String[] args) throws IOException {
  168.         new Gui();
  169.     }
  170.  
  171.  
  172.     @Override
  173.     public void actionPerformed(ActionEvent e) {
  174.  
  175.     }
  176.  
  177.     public class DashBoard implements ActionListener {
  178.  
  179.         @Override
  180.         public void actionPerformed(ActionEvent e) {
  181.             if ((userNameTextField.getText().equals("admin") && passwordField.getText().equals("admin"))) {
  182.                 String[] info;
  183.                 String id;
  184.  
  185.                 dashboardFrame.setVisible(true);
  186.                 dashboardFrame.setSize(500, 700);
  187.                 dashboardFrame.setLayout(null);
  188.  
  189.                 dashboardFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  190.  
  191. //            JMenuBar menuBar = new JMenuBar();
  192. //            dashboardFrame.add(menuBar);
  193. //            menuBar.setBounds(0,0,800,30);
  194. //            menuBar.setVisible(true);
  195. //            JMenuItem products = new JMenuItem("Products");
  196. //            menuBar.add(products);
  197. //            products.setBounds(0,0,100,20);
  198.  
  199.  
  200.                 dashboardFrame.add(searchTextField);
  201.                 searchTextField.setBounds(20, 50, 400, 30);
  202.  
  203.  
  204.                 dashboardFrame.add(searchButton);
  205.                 searchButton.setBounds(430, 48, 100, 30);
  206.  
  207.  
  208.                 dashboardFrame.add(addOrder);
  209.                 addOrder.setBounds(20, 100, 140, 30);
  210.                 addOrder.addActionListener(new AddOrder());
  211.  
  212.  
  213.                 dashboardFrame.add(addProducts);
  214.                 addProducts.setBounds(220, 100, 140, 30);
  215.                 addProducts.addActionListener(new AddNewProduct());
  216.  
  217.  
  218.                 dashboardFrame.add(modifyProducts);
  219.                 modifyProducts.setBounds(420, 100, 140, 30);
  220.                 modifyProducts.addActionListener(new modifyProduct());
  221.  
  222.  
  223.                 dashboardFrame.add(deleteProducts);
  224.                 deleteProducts.setBounds(420, 150, 140, 30);
  225.                 deleteProducts.addActionListener(new DeleteProduct());
  226.  
  227.                 dashboardFrame.add(showProduct);
  228.                 showProduct.setBounds(0, 201, 140, 30);
  229.                 showProduct.setVisible(true);
  230.                 showProduct.addActionListener(new ShowProducts());
  231.                 //showProduct.setBounds();
  232.                 try {
  233.                     id=br.readLine();
  234.                     if (id != null) {
  235.                         try {
  236.                             while (id != null) {
  237.                                 if(id==null)
  238.                                 {
  239.                                     break;
  240.                                 }
  241.                                 if(id!=null&&id!=" ")
  242.                                 {
  243.  
  244.                                     info = id.split(" ");
  245.                                     Products p = new Products(info[0], info[1], Double.parseDouble(info[2]), Integer.parseInt(info[3]));
  246.                                     Store.productsArrayList.add(p);
  247.                                 }
  248.  
  249.                                 id = br.readLine();
  250.  
  251.                             }
  252.                         } catch (IOException e1) {
  253.                             e1.printStackTrace();
  254.                         }
  255.                     }
  256.                 } catch (IOException e1) {
  257.                     e1.printStackTrace();
  258.                 }
  259.  
  260.                 loginFrame.dispose();
  261.  
  262.             } else {
  263.                 JOptionPane.showMessageDialog(null, "Wrong password");
  264.             }
  265.             dashboardFrame.add(bg);
  266.             backGround();
  267.  
  268.         }
  269.         public class AddOrder implements ActionListener{
  270.  
  271.             @Override
  272.             public void actionPerformed(ActionEvent e) {
  273.                 order.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  274.                 order.setVisible(true);
  275.                 order.setSize(500, 700);
  276.                 order.setLayout(null);
  277.  
  278.                 JLabel enterQuantity = new JLabel("Enter Quantity");
  279.                 enterQuantity.setBounds(0,0,100,30);
  280.                 order.add(enterQuantity);
  281.                 enterQuantity.setVisible(true);
  282.  
  283.                 orderQuantity.setVisible(true);
  284.                 order.add(orderQuantity);
  285.                 orderQuantity.setBounds(0,51,100,30);
  286.  
  287.                 order.add(done);
  288.                 done.setVisible(true);
  289.                 done.setBounds(0,101,100,30);
  290.                 done.addActionListener(new OrderModify());
  291.                 order.add(bg);
  292.                 backGround();
  293.  
  294.  
  295.  
  296.             }
  297.         }
  298.         public class  OrderModify implements ActionListener{
  299.  
  300.             @Override
  301.             public void actionPerformed(ActionEvent e) {
  302.                 i = 0;
  303.                 try {
  304.                     while (Store.productsArrayList.get(i) != null) {
  305.                         if (Store.productsArrayList.get(i).productID.equals(searchTextField.getText())) {
  306.  
  307.  
  308.                             foundProduct = true;
  309.                             dashboardFrame.dispose();
  310.                             if (foundProduct) {
  311.  
  312.                                     Store.productsArrayList.get(i).productQuantity-=Integer.parseInt((orderQuantity.getText()));
  313.                                     String line;
  314.                                     int j=0;
  315.                                     try {
  316.  
  317.                                         File inputFile = new File("product.txt");
  318.                                         File tempFile = new File("temp.txt");
  319.  
  320.                                         BufferedReader reader = new BufferedReader(new FileReader(inputFile));
  321.                                         BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
  322.                                         try{
  323.                                             while(Store.productsArrayList.get(j)!=null)
  324.                                             {
  325.                                                 writer.write(Store.productsArrayList.get(j).productName+ " " + Store.productsArrayList.get(j).productID + " " + Store.productsArrayList.get(j).productPrice + " " + Store.productsArrayList.get(j).productQuantity);
  326.                                                 writer.write(System.getProperty("line.separator"));
  327.                                                 writer.flush();
  328.                                                 j++;
  329.                                             }
  330.  
  331.                                             writer.close();
  332.                                             reader.close();
  333.                                         } catch (Exception e1){
  334.  
  335.                                         }
  336.  
  337.                                         boolean successful = tempFile.renameTo(inputFile);
  338.                                     } catch (Exception e1) {
  339.                                         e1.printStackTrace();
  340.                                     }
  341.  
  342.  
  343.                                 break;
  344.                             }
  345.                         }
  346.                         else
  347.                             i++;
  348.                     }
  349.                 } catch (Exception e1) {
  350.                     e1.getMessage();
  351.                 }
  352.  
  353.             }
  354.         }
  355.         public class AddNewProduct implements ActionListener {
  356.  
  357.  
  358.             @Override
  359.             public void actionPerformed(ActionEvent e) {
  360.                 newProduct.setVisible(true);
  361.                 newProduct.setSize(500, 700);
  362.                 newProduct.setLayout(null);
  363.                 newProduct.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  364.  
  365.  
  366.                 newProduct.add(productID);
  367.                 productID.setBounds(20, 40, 100, 50);
  368.  
  369.  
  370.                 newProduct.add(productName);
  371.                 productName.setBounds(20, 80, 100, 50);
  372.  
  373.  
  374.                 newProduct.add(productPrice);
  375.                 productPrice.setBounds(20, 120, 100, 50);
  376.  
  377.  
  378.                 newProduct.add(productQuantity);
  379.                 productQuantity.setBounds(20, 160, 100, 50);
  380.  
  381.  
  382.                 newProduct.add(productIDtext);
  383.                 productIDtext.getText();
  384.                 productIDtext.setText("");
  385.                 productIDtext.setBounds(120, 55, 130, 25);
  386.  
  387.  
  388.                 newProduct.add(productNameText);
  389.                 productNameText.getText();
  390.                 productNameText.setText("");
  391.                 productNameText.setBounds(120, 95, 130, 25);
  392.  
  393.  
  394.                 newProduct.add(priceText);
  395.                 priceText.getText();
  396.                 priceText.setText("");
  397.                 priceText.setBounds(120, 135, 130, 25);
  398.  
  399.  
  400.                 newProduct.add(quantitytext);
  401.                 quantitytext.getText();
  402.                 quantitytext.setText("");
  403.  
  404.                 quantitytext.setBounds(120, 175, 130, 25);
  405.  
  406.  
  407.                 JButton done = new JButton("Done");
  408.                 newProduct.add(done);
  409.                 done.setBounds(160, 260, 100, 25);
  410.                 done.addActionListener(new AddProducts());
  411.  
  412.                 JButton back = new JButton("Back");
  413.                 newProduct.add(back);
  414.                 back.setBounds(20, 260, 100, 25);
  415.  
  416.                 back.addActionListener(new DashBoard());
  417.                 newProduct.add(bg);
  418.                 backGround();
  419.  
  420.                 dashboardFrame.dispose();
  421.  
  422.  
  423.             }
  424.         }
  425.  
  426.         public class AddProducts implements ActionListener {
  427.  
  428.             @Override
  429.             public void actionPerformed(ActionEvent e) {
  430.  
  431.                 price = Double.parseDouble(priceText.getText());
  432.  
  433.                 quantity = Integer.parseInt(quantitytext.getText());
  434.                 Products p = new Products(productNameText.getText(), productIDtext.getText(), price, quantity);
  435.                 Store.productsArrayList.add(p);
  436.                 try {
  437.                     //PrintWriter pw = new PrintWriter(new File("product.txt"));
  438.                     //BufferedWriter bw = new BufferedWriter(new File("product.txt"),true)
  439.                     fw.write(productNameText.getText() + " " + productIDtext.getText() + " " + price + " " + quantity);
  440.                     fw.write(System.getProperty("line.separator"));
  441.                     fw.flush();
  442.  
  443.                 } catch (Exception e1) {
  444.                     e1.printStackTrace();
  445.                 }
  446.  
  447.  
  448.             }
  449.         }
  450.  
  451.         public class modifyProduct implements ActionListener {
  452.  
  453.  
  454.             @Override
  455.             public void actionPerformed(ActionEvent e) {
  456.                 modifyProduct.setVisible(true);
  457.                 modifyProduct.setSize(500, 700);
  458.                 modifyProduct.setLayout(null);
  459.                 modifyProduct.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  460.  
  461.                 foundProduct = false;
  462.                 modifyProduct.add(modproductID);
  463.  
  464.                 modproductID.setBounds(20, 40, 100, 50);
  465.  
  466.  
  467.                 modifyProduct.add(modproductName);
  468.                 modproductName.setBounds(20, 80, 100, 50);
  469.  
  470.  
  471.                 modifyProduct.add(modproductPrice);
  472.                 modproductPrice.setBounds(20, 120, 100, 50);
  473.  
  474.  
  475.                 modifyProduct.add(modproductQuantity);
  476.                 modproductQuantity.setBounds(20, 160, 100, 50);
  477.  
  478.  
  479.                 modifyProduct.add(productIDtext);
  480.                 productIDtext.getText();
  481.                 productIDtext.setText("");
  482.                 productIDtext.setBounds(120, 55, 130, 25);
  483.  
  484.  
  485.                 modifyProduct.add(productNameText);
  486.                 productNameText.getText();
  487.                 productNameText.setText("");
  488.                 productNameText.setBounds(120, 95, 130, 25);
  489.  
  490.  
  491.                 modifyProduct.add(priceText);
  492.                 priceText.getText();
  493.                 priceText.setText("");
  494.                 priceText.setBounds(120, 135, 130, 25);
  495.  
  496.  
  497.                 modifyProduct.add(quantitytext);
  498.                 quantitytext.getText();
  499.                 quantitytext.setText("");
  500.  
  501.                 quantitytext.setBounds(120, 175, 130, 25);
  502.  
  503.  
  504.                 modifyProduct.add(done);
  505.                 done.setBounds(160, 260, 100, 25);
  506.  
  507.  
  508.                 modifyProduct.add(back);
  509.                 back.setBounds(20, 260, 100, 25);
  510.                 back.addActionListener(new DashBoard());
  511.  
  512.                 i = 0;
  513.                 try {
  514.                     while (Store.productsArrayList.get(i) != null) {
  515.                         if (Store.productsArrayList.get(i).productID.equals(searchTextField.getText())) {
  516.  
  517.                             done.addActionListener(new Modifying());
  518.                             foundProduct = true;
  519.                             dashboardFrame.dispose();
  520.                             if (foundProduct) {
  521.                                 j = i;
  522.                                 break;
  523.                             }
  524.                         }
  525.                         i++;
  526.                     }
  527.                 } catch (Exception e1) {
  528.                     e1.getMessage();
  529.                 }
  530.  
  531.  
  532.                 modifyProduct.add(bg);
  533.                 backGround();
  534.             }
  535.         }
  536.  
  537.         public class Modifying implements ActionListener {
  538.  
  539.             @Override
  540.             public void actionPerformed(ActionEvent e) {
  541.                 foundProduct = true;
  542.  
  543.                 price = Double.parseDouble(priceText.getText());
  544.  
  545.                 quantity = Integer.parseInt(quantitytext.getText());
  546.                 Store.productsArrayList.get(i).productName = productNameText.getText();
  547.                 Store.productsArrayList.get(i).productID = productIDtext.getText();
  548.                 Store.productsArrayList.get(i).productPrice = price;
  549.                 Store.productsArrayList.get(i).productQuantity = quantity;
  550.                 System.out.println(Store.productsArrayList.get(i).productName + Store.productsArrayList.get(i).productID + Store.productsArrayList.get(i).productPrice + Store.productsArrayList.get(i).productQuantity);
  551.                 String line;
  552.                 int i=0;
  553.                 try {
  554.  
  555.                     File inputFile = new File("product.txt");
  556.                     File tempFile = new File("temp.txt");
  557.  
  558.                     BufferedReader reader = new BufferedReader(new FileReader(inputFile));
  559.                     BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
  560.                     try{
  561.                         while(Store.productsArrayList.get(i)!=null)
  562.                         {
  563.                             writer.write(Store.productsArrayList.get(i).productName+ " " + Store.productsArrayList.get(i).productID + " " + Store.productsArrayList.get(i).productPrice + " " + Store.productsArrayList.get(i).productQuantity);
  564.                             writer.write(System.getProperty("line.separator"));
  565.                             writer.flush();
  566.                             i++;
  567.                         }
  568.  
  569.                         writer.close();
  570.                         reader.close();
  571.                     } catch (Exception e1){
  572.  
  573.                     }
  574.  
  575.                     boolean successful = tempFile.renameTo(inputFile);
  576.                 } catch (Exception e1) {
  577.                     e1.printStackTrace();
  578.                 }
  579.  
  580.             }
  581.         }
  582.  
  583.         public class DeleteProduct implements ActionListener {
  584.  
  585.             @Override
  586.             public void actionPerformed(ActionEvent e) {
  587.                 delete.setVisible(true);
  588.                 delete.setSize(500, 700);
  589.                 delete.setLayout(null);
  590.                 delete.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  591.                 i = 0;
  592.                 try {
  593.                     while (Store.productsArrayList.get(i) != null) {
  594.                         if (Store.productsArrayList.get(i).productID.equals(searchTextField.getText())) {
  595.                             delete.add(label);
  596.                             label.setVisible(true);
  597.                             label.setBounds(0,0,300,30);
  598.                             label.setText(Store.productsArrayList.get(i).productName + " " + Store.productsArrayList.get(i).productID + " " + Store.productsArrayList.get(i).productPrice + " " + Store.productsArrayList.get(i).productQuantity);
  599.                             done.addActionListener(new Modifying());
  600.                             foundProduct = true;
  601.                             dashboardFrame.dispose();
  602. /*                            File tempFile = new File("temp.txt");
  603.                             File prevFile = new File("product.txt");
  604.                             BufferedWriter bw = new BufferedWriter(new FileWriter(tempFile));
  605.  
  606.                             String lineToRemove =Store.productsArrayList.get(i).productName + " " + Store.productsArrayList.get(i).productID + " " + Store.productsArrayList.get(i).productPrice + " " + Store.productsArrayList.get(i).productQuantity;
  607.                             String currentLine;
  608.                             while((currentLine = br.readLine()) != null) {
  609.                                 // trim newline when comparing with lineToRemove
  610.                                 String trimmedLine = currentLine.trim();
  611.                                 if(trimmedLine.equals(lineToRemove)) continue;
  612.                                 bw.write(currentLine + System.getProperty("line.separator"));
  613.                             }
  614.                             bw.close();
  615.                             br.close();
  616.                             tempFile.renameTo(prevFile);*/
  617.  
  618.  
  619.                             if (foundProduct) {
  620.                                 File inputFile = new File("product.txt");
  621.                                 File tempFile = new File("temp.txt");
  622.  
  623.                                 BufferedReader reader = new BufferedReader(new FileReader(inputFile));
  624.                                 BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
  625.  
  626.                                 String lineToRemove = Store.productsArrayList.get(i).productName + " " + Store.productsArrayList.get(i).productID + " " + Store.productsArrayList.get(i).productPrice + " " + Store.productsArrayList.get(i).productQuantity;
  627.                                 String currentLine;
  628.  
  629.                                 while((currentLine = reader.readLine()) != null) {
  630.                                     // trim newline when comparing with lineToRemove
  631.                                     String trimmedLine = currentLine.trim();
  632.                                     if(trimmedLine.equals(lineToRemove)) continue;
  633.                                     writer.write(currentLine + System.getProperty("line.separator"));
  634.                                 }
  635.                                 //writer.close();
  636.                                 //reader.close();
  637.                                 boolean successful = tempFile.renameTo(inputFile);
  638.                                 writer.close();
  639.                                 reader.close();
  640.                                 Store.productsArrayList.remove(i);
  641.                                 j = i;
  642.                                 break;
  643.                             }
  644.                         }
  645.                         i++;
  646.                     }
  647.                 } catch (Exception e1) {
  648.                     e1.getMessage();
  649.                 }
  650.                 if(!foundProduct)
  651.                 {
  652.                     delete.add(label);
  653.                     label.setVisible(true);
  654.                     label.setBounds(0,0,300,30);
  655.                     label.setText("Not Found");
  656.                 }
  657.                 delete.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  658.                 backGround();
  659.  
  660.                 dashboardFrame.dispose();
  661.             }
  662.         }
  663.  
  664.         public class ShowProducts implements ActionListener {
  665.  
  666.             @Override
  667.             public void actionPerformed(ActionEvent e) {
  668.                 i = 0;
  669.                 int y =251;
  670.  
  671.  
  672.    /*             if(Store.productsArrayList!=null)
  673.                 {
  674.                     try{
  675.                         for(i=0;Store.productsArrayList.get(i)!=null;i++){
  676.  
  677.                             dashboardFrame.add(label);
  678.                             label.setVisible(true);
  679.                             label.setBounds(0,y,100,30);
  680.                             label.setText("");
  681.                             y+=30;
  682.  
  683.  
  684.                         }
  685.                     } catch (Exception e2){
  686.  
  687.                     }*/
  688.                 y=251;
  689.                 String product = "";
  690.                 try{
  691.                     i=0;
  692.                     while(Store.productsArrayList.get(i)!=null){
  693.  
  694.  
  695.                             /*label.setText(Store.productsArrayList.get(i).productName + " " + Store.productsArrayList.get(i).productID + " " + Store.productsArrayList.get(i).productPrice + " " + Store.productsArrayList.get(i).productQuantity);
  696.                             */
  697.                         product+=Store.productsArrayList.get(i).productName + " " + Store.productsArrayList.get(i).productID + " " + Store.productsArrayList.get(i).productPrice + " " + Store.productsArrayList.get(i).productQuantity+"\n";
  698.                         //y+=30;
  699.                         i++;
  700.  
  701.  
  702.                     }
  703.                 } catch (Exception e2){
  704.  
  705.                 }
  706.                 dashboardFrame.add(label);
  707.                 label.setVisible(true);
  708.                 label.setBounds(0,251,500,300);
  709.                 label.setText(convertToMultiline(product));
  710.                 //label.setText(product);
  711.                 //label.
  712.  
  713.  
  714.  
  715.             }
  716.             public String convertToMultiline(String forMultiline){
  717.                 return "<html>"+forMultiline.replace("\n","<br>");
  718.             }
  719.  
  720.         }
  721.         void showProductInfo() {
  722.             int y = 251;
  723.             if (Store.productsArrayList != null) {
  724.  
  725.  
  726.                 try {
  727.                     for (i = 0; Store.productsArrayList.get(i) != null; i++) {
  728.                         dashboardFrame.add(showProductInfo);
  729.                         showProductInfo.setVisible(true);
  730.                         showProductInfo.setBounds(0, y, 100, 30);
  731.                         showProductInfo.setText(Store.productsArrayList.get(i).productName + " " + Store.productsArrayList.get(i).productID + " " + Store.productsArrayList.get(i).productPrice + " " + Store.productsArrayList.get(i).productQuantity);
  732.                         y += 30;
  733.                     }
  734.                 } catch (Exception e2) {
  735.  
  736.                 }
  737.             }
  738.  
  739.         }
  740.  
  741.  
  742.     }
  743.     void backGround()
  744.     {
  745. /*        loginFrame.add(bg);
  746.         dashboardFrame.add(bg);
  747.         modifyProduct.add(bg);
  748.         newProduct.add(bg);
  749.         delete.add(bg);
  750.         order.add(bg);*/
  751.         bg.setBounds(0,0,500,700);
  752.         bg.setVisible(true);
  753.  
  754.  
  755.     }
  756. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement