Advertisement
Guest User

AmrPOS

a guest
Dec 11th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 20.49 KB | None | 0 0
  1. import java.awt.event.*;
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.util.*;
  5. import javax.swing.table.*;
  6.  
  7. class MainGUI extends JFrame implements ActionListener {
  8.   static MainGUI maingui;
  9.  
  10.   // create a frame
  11.     static JFrame frame;
  12.  
  13.     // create components
  14.     static JTextField labeltotal;
  15.     static JTextField labelsearch;
  16.     static JTextField labelcustom;
  17.   static JLabel iconsearch;
  18.   static JButton iconedit, iconpurchase;
  19.     static JButton butttonlib, buttoncus;
  20.   static JButton buttoncreate, buttondone;
  21.     static JButton button0, button1, button2, button3, button4, button5, button6, button7, button8, button9, buttonc, buttonadd;
  22.   static JTable maintable;
  23.   static DefaultTableModel model;
  24.   static JScrollPane sp;
  25.  
  26.   static Boolean edit = false;
  27.  
  28.     // store operands
  29.     static String s0 = "";
  30.   static String st;
  31.  
  32.   static String[] columnNames = { "Name", "Price", "Category", "SKU", "Description", "Count" };
  33.  
  34.   // create an itemframe
  35.     static JFrame itemframe;
  36.  
  37.     // create components
  38.   static JTextField labelname;
  39.   static DefaultListModel listModel;
  40.   static JTextField labelcategory;
  41.     static JTextField labelprice;
  42.   static JTextField labelSKU;
  43.   static JTextField labeldesc;
  44.  
  45.   static JButton buttonexit, buttonsave, buttondelete;
  46.  
  47.   static Boolean edititem;  
  48.  
  49.   static Boolean purchase;  
  50.   static JFrame purchaseframe;
  51.   static JLabel currentsale;
  52.     static JTextField labelpurchasetotal;
  53.   static JButton buttonexitpurchase, buttonclear;
  54.   static JTable purchasetable;
  55.   static JScrollPane purchasesp;
  56.   static DefaultTableModel purchasemodel;
  57.   static String[] purchasecolumnNames = { "Name", "Count", "Price", "Delete" };
  58.  
  59.     // default constructor
  60.     MainGUI()
  61.     {
  62.     st = "0";
  63.     }
  64.  
  65.     // main function
  66.     public static void create()
  67.     {
  68.         // create a frame
  69.         frame = new JFrame("Amr POS");
  70.  
  71.         // create a object of class
  72.         maingui = new MainGUI();
  73.  
  74.         // create a textfield
  75.         labeltotal = new JTextField(24);
  76.         labeltotal.setText("Charge Rp. 0");
  77.  
  78.         labelcustom = new JTextField(24);
  79.         labelcustom.setText("Rp. 0");
  80.  
  81.         // set the textfield to non editable
  82.         labeltotal.setEditable(false);
  83.         labelcustom.setEditable(false);
  84.  
  85.     ImageIcon imageIcon = new ImageIcon("resources/search-button-icon.png");
  86.     Image image = imageIcon.getImage();
  87.     Image newimg = image.getScaledInstance(18, 18, Image.SCALE_SMOOTH);
  88.     imageIcon = new ImageIcon(newimg);
  89.    
  90.     iconsearch = new JLabel("");
  91.     iconsearch.setIcon(imageIcon);
  92.     iconsearch.setPreferredSize(new Dimension(18, 18));
  93.  
  94.     labelsearch = new JTextField(19);
  95.     labelsearch.setText("Search");
  96.     labelsearch.addMouseListener(new MouseAdapter()
  97.     {
  98.         public void mouseClicked(MouseEvent e)
  99.         {
  100.           if(labelsearch.getText().equals("Search"))
  101.           {
  102.             labelsearch.setText("");
  103.           }          
  104.         }
  105.     }
  106.     );
  107.  
  108.     imageIcon = new ImageIcon("resources/edit-button-icon.jpg");
  109.     image = imageIcon.getImage();
  110.     newimg = image.getScaledInstance(16, 16, Image.SCALE_SMOOTH);
  111.     imageIcon = new ImageIcon(newimg);
  112.  
  113.     iconedit = new JButton("", imageIcon);
  114.     iconedit.setActionCommand("edit");
  115.     iconedit.setPreferredSize(new Dimension(18, 18));
  116.     iconedit.setBorder(BorderFactory.createEmptyBorder());
  117.  
  118.     //create menubutton
  119.     butttonlib = new JButton("Library");
  120.     butttonlib.setPreferredSize(new Dimension(120, 50));
  121.  
  122.     buttoncus = new JButton("Custom");
  123.     buttoncus.setPreferredSize(new Dimension(120, 50));
  124.  
  125.     // create submenu buttons
  126.         buttoncreate = new JButton("CREATE NEW ITEM");
  127.     buttoncreate.setPreferredSize(new Dimension(240, 50));
  128.     buttondone = new JButton("DONE");
  129.     buttondone.setPreferredSize(new Dimension(240, 50));
  130.    
  131.     imageIcon = new ImageIcon("resources/purchase-icon.png");
  132.     image = imageIcon.getImage();
  133.     newimg = image.getScaledInstance(40, 40, Image.SCALE_SMOOTH);
  134.     imageIcon = new ImageIcon(newimg);
  135.    
  136.     iconpurchase = new JButton("", imageIcon);
  137.     iconpurchase.setActionCommand("Purchase");
  138.     iconpurchase.setPreferredSize(new Dimension(240, 50));
  139.  
  140.     // create number buttons
  141.         button0 = new JButton("0");
  142.     button0.setPreferredSize(new Dimension(78, 50));
  143.         button1 = new JButton("1");
  144.     button1.setPreferredSize(new Dimension(78, 50));
  145.         button2 = new JButton("2");
  146.     button2.setPreferredSize(new Dimension(78, 50));
  147.         button3 = new JButton("3");
  148.     button3.setPreferredSize(new Dimension(78, 50));
  149.         button4 = new JButton("4");
  150.     button4.setPreferredSize(new Dimension(78, 50));
  151.         button5 = new JButton("5");
  152.     button5.setPreferredSize(new Dimension(78, 50));
  153.         button6 = new JButton("6");
  154.     button6.setPreferredSize(new Dimension(78, 50));
  155.         button7 = new JButton("7");
  156.     button7.setPreferredSize(new Dimension(78, 50));
  157.         button8 = new JButton("8");
  158.     button8.setPreferredSize(new Dimension(78, 50));
  159.         button9 = new JButton("9");
  160.     button9.setPreferredSize(new Dimension(78, 50));
  161.  
  162.         // create operator buttons
  163.         buttonadd = new JButton("+");
  164.     buttonadd.setPreferredSize(new Dimension(78, 50));
  165.  
  166.         // create C button
  167.         buttonc = new JButton("C");
  168.     buttonc.setPreferredSize(new Dimension(78, 50));
  169.  
  170.         // create a panel
  171.         JPanel panel = new JPanel();
  172.  
  173.     // Initializing the JTable
  174.     model = new DefaultTableModel(columnNames, 0);
  175.     maintable = new JTable(model);
  176.  
  177.     maintable.setTableHeader(null);
  178.     maintable.setShowGrid(false);
  179.     maintable.setDefaultEditor(Object.class, null);
  180.     maintable.getColumnModel().getColumn(2).setMinWidth(0);
  181.     maintable.getColumnModel().getColumn(2).setMaxWidth(0);
  182.     maintable.getColumnModel().getColumn(2).setWidth(0);
  183.     maintable.getColumnModel().getColumn(3).setMinWidth(0);
  184.     maintable.getColumnModel().getColumn(3).setMaxWidth(0);
  185.     maintable.getColumnModel().getColumn(3).setWidth(0);
  186.     maintable.getColumnModel().getColumn(4).setMinWidth(0);
  187.     maintable.getColumnModel().getColumn(4).setMaxWidth(0);
  188.     maintable.getColumnModel().getColumn(4).setWidth(0);
  189.     maintable.getColumnModel().getColumn(5).setMinWidth(0);
  190.     maintable.getColumnModel().getColumn(5).setMaxWidth(0);
  191.     maintable.getColumnModel().getColumn(5).setWidth(0);
  192.  
  193.     maintable.addMouseListener(new MouseAdapter()
  194.     {
  195.       public void mouseClicked(MouseEvent event)
  196.       {
  197.         if (!edit)
  198.         {
  199.           int row = maintable.rowAtPoint(event.getPoint());
  200.           int col = 1;
  201.           int te = 0;
  202.           s0 = maintable.getValueAt(row, col).toString();
  203.           te = (Integer.parseInt(s0) + Integer.parseInt(st));
  204.           st = Integer.toString(te);
  205.           labeltotal.setText("Charge Rp. " + st);
  206.  
  207.           model.setValueAt(Integer.parseInt(maintable.getValueAt(row, 5).toString()) + 1, row, 5);
  208.  
  209.           maintable.setModel(model);
  210.         }
  211.         else
  212.         {
  213.           createItemGUI("edit", maintable.rowAtPoint(event.getPoint()));
  214.         }
  215.       }
  216.     }
  217.     );
  218.  
  219.     // adding it to JScrollPane
  220.     sp = new JScrollPane(maintable);
  221.     sp.setPreferredSize(new Dimension(240, 150));
  222.        
  223.     // add action listeners
  224.     iconedit.addActionListener(maingui);   
  225.     iconpurchase.addActionListener(maingui);   
  226.     butttonlib.addActionListener(maingui); 
  227.     buttoncus.addActionListener(maingui);  
  228.  
  229.         buttoncreate.addActionListener(maingui);
  230.     buttondone.addActionListener(maingui);
  231.  
  232.     button9.addActionListener(maingui);
  233.         button8.addActionListener(maingui);
  234.         button7.addActionListener(maingui);
  235.         button6.addActionListener(maingui);
  236.         button5.addActionListener(maingui);
  237.         button4.addActionListener(maingui);
  238.         button3.addActionListener(maingui);
  239.         button2.addActionListener(maingui);
  240.         button1.addActionListener(maingui);
  241.         button0.addActionListener(maingui);
  242.         buttonc.addActionListener(maingui);
  243.         buttonadd.addActionListener(maingui);
  244.  
  245.         // add elements to panel
  246.         panel.add(labeltotal);
  247.     panel.add(butttonlib);
  248.     panel.add(buttoncus);
  249.     panel.add(iconsearch);
  250.     panel.add(labelsearch);
  251.     panel.add(iconedit);
  252.  
  253.         panel.add(buttoncreate);
  254.     panel.add(sp);
  255.     panel.add(buttondone);
  256.     panel.add(iconpurchase);
  257.  
  258.     panel.add(labelcustom);
  259.     panel.add(button1);
  260.         panel.add(button2);
  261.         panel.add(button3);
  262.         panel.add(button4);
  263.         panel.add(button5);
  264.         panel.add(button6);
  265.         panel.add(button7);
  266.         panel.add(button8);
  267.         panel.add(button9);
  268.         panel.add(buttonc);
  269.         panel.add(button0);
  270.         panel.add(buttonadd);
  271.  
  272.         // add panel to frame
  273.         frame.add(panel);
  274.  
  275.         frame.setSize(280, 500);
  276.     maingui.startLibrary();
  277.         frame.show();
  278.   }
  279.  
  280.   public static void createItemGUI(String buffer, int row)
  281.     {
  282.     if(buffer.compareTo("new") == 0)
  283.     {
  284.       edititem = false;
  285.     }
  286.     else
  287.     {
  288.       edititem = true;
  289.     }
  290.  
  291.     if(!edititem)
  292.     {
  293.       // create an itemframe
  294.       itemframe = new JFrame("Create New Item");
  295.     }
  296.     else
  297.     {
  298.       itemframe = new JFrame("Edit Item");
  299.     }
  300.         // create a textfield
  301.  
  302.     labelname = new JTextField(24);
  303.     labelprice = new JTextField(24);
  304.     labelcategory = new JTextField(24);
  305.     labelSKU = new JTextField(24);
  306.     labeldesc = new JTextField(24);
  307.     if(edititem)
  308.     {
  309.       labelname.setText(maintable.getValueAt(row, 0).toString());
  310.       labelprice.setText(maintable.getValueAt(row, 1).toString());
  311.       labelcategory.setText(maintable.getValueAt(row, 2).toString());
  312.       labelSKU.setText(maintable.getValueAt(row, 3).toString());
  313.       labeldesc.setText(maintable.getValueAt(row, 4).toString());
  314.     }
  315.     else
  316.     {
  317.       labelname.setText("Item Name");
  318.       labelprice.setText("Price");
  319.       labelcategory.setText("Category");
  320.       labelSKU.setText("SKU");
  321.       labeldesc.setText("Description");  
  322.     }
  323.    
  324.     labelname.addMouseListener(new MouseAdapter()
  325.     {
  326.         public void mouseClicked(MouseEvent e)
  327.         {
  328.           if(labelname.getText().equals("Item Name"))
  329.           {
  330.             labelname.setText("");
  331.           }          
  332.         }
  333.     }
  334.     );
  335.    
  336.     labelcategory.addMouseListener(new MouseAdapter()
  337.     {
  338.         public void mouseClicked(MouseEvent e)
  339.         {
  340.           if(labelcategory.getText().equals("Category"))
  341.           {
  342.             labelcategory.setText("");
  343.           }          
  344.         }
  345.     }
  346.     );
  347.  
  348.     labelprice.addMouseListener(new MouseAdapter()
  349.     {
  350.         public void mouseClicked(MouseEvent e)
  351.         {
  352.           if(labelprice.getText().equals("Price"))
  353.           {
  354.             labelprice.setText("");
  355.           }          
  356.         }
  357.     }
  358.     );
  359.        
  360.     labelSKU.addMouseListener(new MouseAdapter()
  361.     {
  362.         public void mouseClicked(MouseEvent e)
  363.         {
  364.           if(labelSKU.getText().equals("SKU"))
  365.           {
  366.             labelSKU.setText("");
  367.           }          
  368.         }
  369.     }
  370.     );
  371.    
  372.     labeldesc.addMouseListener(new MouseAdapter()
  373.     {
  374.         public void mouseClicked(MouseEvent e)
  375.         {
  376.           if(labeldesc.getText().equals("Description"))
  377.           {
  378.             labeldesc.setText("");
  379.           }          
  380.         }
  381.     }
  382.     );
  383.  
  384.     buttonexit = new JButton("X");
  385.     buttonexit.setPreferredSize(new Dimension(50, 50));
  386.  
  387.         buttonsave = new JButton("SAVE");
  388.     buttonsave.setPreferredSize(new Dimension(190, 50));
  389.  
  390.     buttondelete = new JButton("DELETE");
  391.     buttondelete.setPreferredSize(new Dimension(240, 50));
  392.  
  393.     // create a itempanel
  394.         JPanel itempanel = new JPanel();
  395.        
  396.     // add action listeners
  397.         buttonsave.addActionListener(maingui);
  398.     buttonexit.addActionListener(maingui);
  399.     buttondelete.addActionListener(maingui);
  400.  
  401.         // add elements to itempanel
  402.     itempanel.add(labelname);
  403.     itempanel.add(labelcategory);
  404.     itempanel.add(labelprice);
  405.     itempanel.add(labelSKU);
  406.     itempanel.add(labeldesc);
  407.         itempanel.add(buttonexit);
  408.         itempanel.add(buttonsave);
  409.  
  410.     if(edititem)
  411.     {
  412.       itempanel.add(buttondelete);
  413.     }
  414.         // add itempanel to itemframe
  415.         itemframe.add(itempanel);
  416.  
  417.         itemframe.setSize(300, 500);
  418.         itemframe.show();
  419.   }
  420.  
  421.   public static void createPurchaseGUI()
  422.     {
  423.     int total = 0;
  424.     Object[] object = new Object[4];
  425.  
  426.     purchaseframe = new JFrame("Purchase");
  427.     purchase = true;
  428.     currentsale = new JLabel("CURRENT SALE");
  429.     labelpurchasetotal = new JTextField(24);
  430.         labelpurchasetotal.setEditable(false);
  431.     labelpurchasetotal.setText("Charge Rp. " + st);
  432.  
  433.     //Initializing the JTable
  434.     purchasemodel = new DefaultTableModel(purchasecolumnNames, 0);
  435.  
  436.     for(int i = 0; i < maintable.getRowCount(); i++)
  437.     {
  438.       if(Integer.parseInt(maintable.getValueAt(i, 5).toString()) > 0)
  439.       {
  440.         object[0] = maintable.getValueAt(i, 0).toString();
  441.         object[1] = ("x" + maintable.getValueAt(i, 5).toString());
  442.         object[2] = Integer.parseInt(maintable.getValueAt(i, 1).toString()) * Integer.parseInt(maintable.getValueAt(i, 5).toString());
  443.         object[3] = "X";
  444.         total = total + Integer.parseInt(maintable.getValueAt(i, 1).toString()) * Integer.parseInt(maintable.getValueAt(i, 5).toString());
  445.         purchasemodel.addRow(object);
  446.       }
  447.     }
  448.  
  449.     if (total < Integer.parseInt(st))
  450.     {
  451.       object[0] = "Custom";
  452.       object[1] = "";
  453.       object[2] = Integer.parseInt(st) - total;
  454.       object[3] = "X";
  455.      
  456.       purchasemodel.addRow(object);
  457.     }
  458.  
  459.     purchasetable = new JTable(purchasemodel);
  460.     purchasetable.getColumnModel().getColumn(3).setMinWidth(11);
  461.     purchasetable.getColumnModel().getColumn(3).setMaxWidth(11);
  462.     purchasetable.getColumnModel().getColumn(3).setWidth(11);
  463.     purchasetable.setTableHeader(null);
  464.     purchasetable.setShowGrid(false);
  465.     purchasetable.setDefaultEditor(Object.class, null);
  466.  
  467.     purchasetable.addMouseListener(new MouseAdapter()
  468.     {
  469.       public void mouseClicked(MouseEvent event)
  470.       {
  471.         int col = purchasetable.columnAtPoint(event.getPoint());
  472.         int row = purchasetable.rowAtPoint(event.getPoint());
  473.         if (col == 3)
  474.         {
  475.           int te = 0;
  476.           s0 = purchasetable.getValueAt(row, 2).toString();
  477.           te = (Integer.parseInt(st) - Integer.parseInt(s0));
  478.           st = Integer.toString(te);
  479.           labelpurchasetotal.setText("Charge Rp. " + st);
  480.           labeltotal.setText("Charge Rp. " + st);
  481.          
  482.           for (int i = 0; i < model.getRowCount(); i++)
  483.           {
  484.             if(model.getValueAt(i, 0) == purchasetable.getValueAt(row, 0))
  485.             {
  486.               model.setValueAt(0, i, 5);
  487.             }
  488.           }
  489.           int numRows = purchasetable.getSelectedRows().length;
  490.           for(int i = 0; i < numRows ; i++)
  491.           {
  492.             purchasemodel.removeRow(purchasetable.getSelectedRow());
  493.           }
  494.           purchasetable.setModel(purchasemodel);
  495.         }
  496.       }
  497.     }
  498.     );
  499.  
  500.     purchasesp = new JScrollPane(purchasetable);
  501.     purchasesp.setPreferredSize(new Dimension(240, 150));
  502.    
  503.     buttonexitpurchase = new JButton("X");
  504.     buttonexitpurchase.setPreferredSize(new Dimension(50, 50));
  505.  
  506.         buttonclear = new JButton("Clear Sale");
  507.     buttonclear.setPreferredSize(new Dimension(190, 50));
  508.  
  509.     // create a purchasepanel
  510.         JPanel purchasepanel = new JPanel();
  511.        
  512.     // add action listeners
  513.         buttonclear.addActionListener(maingui);
  514.     buttonexitpurchase.addActionListener(maingui);
  515.  
  516.  
  517.         // add elements to purchasepanel
  518.         purchasepanel.add(currentsale);
  519.         purchasepanel.add(purchasesp);
  520.         purchasepanel.add(labelpurchasetotal);
  521.         purchasepanel.add(buttonexitpurchase);
  522.         purchasepanel.add(buttonclear);
  523.  
  524.         // add purchasepanel to purchaseframe
  525.         purchaseframe.add(purchasepanel);
  526.         purchaseframe.setSize(300, 500);
  527.         purchaseframe.show();
  528.     }
  529.  
  530.   public static void startLibrary()
  531.   {
  532.     butttonlib.setEnabled(false);
  533.     buttoncus.setEnabled(true);
  534.     iconsearch.setVisible(false);
  535.     labelsearch.setVisible(false);
  536.     labelcustom.setVisible(false);
  537.     iconedit.setVisible(true);
  538.  
  539.     buttoncreate.setVisible(false);
  540.  
  541.     sp.setVisible(true);
  542.  
  543.     buttondone.setVisible(false);
  544.     iconpurchase.setVisible(true);
  545.  
  546.     button9.setVisible(false);
  547.         button8.setVisible(false);
  548.         button7.setVisible(false);
  549.         button6.setVisible(false);
  550.         button5.setVisible(false);
  551.         button4.setVisible(false);
  552.         button3.setVisible(false);
  553.         button2.setVisible(false);
  554.         button1.setVisible(false);
  555.         button0.setVisible(false);
  556.         buttonc.setVisible(false);
  557.         buttonadd.setVisible(false);
  558.   }
  559.  
  560.   public static void starteditLibrary()
  561.   {
  562.     butttonlib.setEnabled(false);
  563.     buttoncus.setEnabled(false);
  564.     labelcustom.setVisible(false);
  565.     iconedit.setVisible(false);
  566.  
  567.     buttoncreate.setVisible(true);
  568.     iconpurchase.setVisible(false);
  569.  
  570.     buttondone.setVisible(true);
  571.   }
  572.  
  573.   public static void startCustom()
  574.   {
  575.     s0 = "";
  576.     labelcustom.setText("Rp. 0");
  577.     butttonlib.setEnabled(true);
  578.     buttoncus.setEnabled(false);
  579.     labelsearch.setVisible(false);
  580.     labelcustom.setVisible(true);
  581.     iconsearch.setVisible(false);
  582.     iconedit.setVisible(false);
  583.  
  584.     buttoncreate.setVisible(false);
  585.    
  586.     sp.setVisible(false);
  587.  
  588.     iconpurchase.setVisible(false);
  589.    
  590.     button9.setVisible(true);
  591.         button8.setVisible(true);
  592.         button7.setVisible(true);
  593.         button6.setVisible(true);
  594.         button5.setVisible(true);
  595.         button4.setVisible(true);
  596.         button3.setVisible(true);
  597.         button2.setVisible(true);
  598.         button1.setVisible(true);
  599.         button0.setVisible(true);
  600.         buttonc.setVisible(true);
  601.         buttonadd.setVisible(true);
  602.   }
  603.  
  604.     public void actionPerformed(ActionEvent event)
  605.     {
  606.         String s = event.getActionCommand();
  607.  
  608.         // if the value is a number
  609.         if ((s.charAt(0) >= '0' && s.charAt(0) <= '9')) {
  610.             // if operand is present then add to second no
  611.             s0 = s0 + s;
  612.  
  613.             // set the value of text
  614.             labelcustom.setText("Rp. " + s0);
  615.         }
  616.         else if (s.equals("C")) {
  617.       s0 = "";
  618.             // set the value of text
  619.             labelcustom.setText("Rp. 0");
  620.         }
  621.         else if (s.charAt(0) == '+') {
  622.             // if there was no operand
  623.             int te = 0;
  624.       if(s0 == "")
  625.       {
  626.         s0 = "0";
  627.       }
  628.       te = (Integer.parseInt(s0) + Integer.parseInt(st));
  629.  
  630.       // convert it to string
  631.       st = Integer.toString(te);
  632.       s0 = "";  
  633.  
  634.         // set the value of text
  635.             labelcustom.setText("Rp. 0");
  636.             labeltotal.setText("Charge Rp. " + st);
  637.         }
  638.     else if (s.equals("Library"))
  639.     {
  640.       startLibrary();
  641.     }
  642.     else if (s.equals("Custom"))
  643.     {
  644.       startCustom();
  645.     }
  646.     else if (s.equals("edit"))
  647.     {
  648.       starteditLibrary();
  649.       edit = true;
  650.     }
  651.     else if (s.equals("Purchase"))
  652.     {
  653.       createPurchaseGUI();
  654.       frame.dispose();
  655.     }
  656.     else if (s.equals("DONE"))
  657.     {
  658.       startLibrary();
  659.       edit = false;
  660.     }
  661.     else if (s.equals("CREATE NEW ITEM"))
  662.     {
  663.       // frame.dispose();
  664.       createItemGUI("new", 0);
  665.     }
  666.     else if (s.equals("SAVE"))
  667.     {
  668.       Object[] row = new Object[6];
  669.       row[0] = (String)labelname.getText();
  670.       row[1] = labelprice.getText();
  671.       row[2] = (String)labelcategory.getText();
  672.       row[3] = (String)labelSKU.getText();
  673.       row[4] = (String)labeldesc.getText();
  674.       row[5] = 0;
  675.       model.addRow(row);
  676.       maintable.setModel(model);
  677.       if(edititem)
  678.       {
  679.         int numRows = maintable.getSelectedRows().length;
  680.         for(int i = 0; i < numRows ; i++)
  681.         {
  682.           model.removeRow(maintable.getSelectedRow());
  683.         }
  684.       }
  685.       itemframe.dispose();
  686.  
  687.       // frame.show();
  688.     }
  689.     else if (s.equals("X"))
  690.     {
  691.       if(purchase == true)
  692.       {
  693.         purchaseframe.dispose();
  694.         frame.show();
  695.       }
  696.       else
  697.       {
  698.         itemframe.dispose();
  699.       }
  700.     }
  701.     else if (s.equals("DELETE"))
  702.     {
  703.       int numRows = maintable.getSelectedRows().length;
  704.       for(int i = 0; i < numRows ; i++)
  705.       {
  706.         model.removeRow(maintable.getSelectedRow());
  707.       }
  708.       itemframe.dispose();
  709.  
  710.     }
  711.     else if (s.equals("Clear Sale"))
  712.     {
  713.       labelcustom.setText("Rp. 0");
  714.       labeltotal.setText("Charge Rp. 0");
  715.       labelpurchasetotal.setText("Charge Rp. 0");
  716.       s0 = "";
  717.       st = "0";
  718.      
  719.       for (int i = 0; i < purchasemodel.getRowCount(); i++)
  720.       {
  721.         purchasemodel.removeRow(i);
  722.       }
  723.       purchasetable.setModel(purchasemodel);
  724.      
  725.       for (int i = 0; i < model.getRowCount(); i++)
  726.       {
  727.         model.setValueAt(0, i, 5);
  728.       }
  729.     }
  730.   }
  731. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement