Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.*;
- import javax.swing.*;
- import java.awt.*;
- import java.util.*;
- import javax.swing.table.*;
- class Menu extends JFrame implements ActionListener {
- static Menu menu;
- static JFrame frame;
- static JTextField TblTotal;
- static JTextField TblCari;
- static JTextField TblCus;
- static JLabel iconcari;
- static JButton iconcus, iconbeli;
- static JButton tombolbarang, tombolcus;
- static JButton buttoncreate, buttondone;
- static JButton
- button0,
- button1,
- button2,
- button3,
- button4,
- button5,
- button6,
- button7,
- button8,
- button9,
- buttoncus,
- buttonforsum;
- static JTable tabel;
- static DefaultTableModel utah;
- static JScrollPane x;
- static Boolean edit = false;
- static String y = "";
- static String pos;
- static String[] kolomNama = { "Nama", "Harga", "Kategori", "IDBarang",
- "Deskripsi", "Count" };
- static DefaultListModel listmodel;
- static JFrame itemframe;
- static JTextField LblNama;
- static JTextField LblKategori;
- static JTextField LblHarga;
- static JTextField LblIDBarang;
- static JTextField Lbldeskripsi;
- static JButton buttonesc, buttonsave, buttondelete;
- static Boolean Custom;
- static Boolean byr;
- static JFrame byrframe;
- static JLabel currentsale;
- static JTextField LblByrTotal;
- static JButton tombolescbyr, tombolclear;
- static JTable byrtable;
- static JScrollPane byrx;
- static DefaultTableModel byrmodel;
- static String[] byrkolomNama = { "Name", "Count", "Price", "Delete" };
- Menu()
- {
- pos = "0";
- }
- public static void create()
- {
- frame = new JFrame("Point Of Sales");
- menu = new Menu();
- TblTotal = new JTextField(24);
- TblTotal.setText("Total Rp. 0");
- TblCus = new JTextField(24);
- TblCus.setText("Rp. 0");
- TblTotal.setEditable(false);
- TblCus.setEditable(false);
- ImageIcon imageIcon =
- new ImageIcon("search-button-icon.png");
- Image image = imageIcon.getImage();
- Image newimg =
- image.getScaledInstance(18, 18, Image.SCALE_SMOOTH);
- imageIcon = new ImageIcon(newimg);
- iconcari = new JLabel("");
- iconcari.setIcon(imageIcon);
- iconcari.setPreferredSize(new Dimension(18, 18));
- TblCari = new JTextField(19);
- TblCari.setText("Cari Barang");
- TblCari.addMouseListener(new MouseAdapter()
- {
- public void mouseClicked(MouseEvent e)
- {
- if(TblCari.getText().equals("Search"))
- {
- TblCari.setText("");
- }
- }
- }
- );
- imageIcon = new ImageIcon("search-button-icon.png");
- image = imageIcon.getImage();
- newimg = image.getScaledInstance(16, 16, Image.SCALE_SMOOTH);
- imageIcon = new ImageIcon(newimg);
- iconcus = new JButton("", imageIcon);
- iconcus.setActionCommand("edit");
- iconcus.setPreferredSize(new Dimension(18, 18));
- iconcus.setBorder(BorderFactory.createEmptyBorder());
- tombolbarang = new JButton("Barang");
- tombolbarang.setPreferredSize(new Dimension(120, 50));
- tombolcus = new JButton("Custom");
- tombolcus.setPreferredSize(new Dimension(120, 50));
- buttoncreate = new JButton("Input Barang Baru");
- buttoncreate.setPreferredSize(new Dimension(240, 50));
- buttondone = new JButton("$ELESAI");
- buttondone.setPreferredSize(new Dimension(240, 50));
- imageIcon = new ImageIcon("byr-icon.png");
- image = imageIcon.getImage();
- newimg = image.getScaledInstance(40, 40, Image.SCALE_SMOOTH);
- imageIcon = new ImageIcon(newimg);
- iconbeli = new JButton("", imageIcon);
- iconbeli.setActionCommand("Bayar");
- iconbeli.setPreferredSize(new Dimension(240, 50));
- button0 = new JButton("0");
- button0.setPreferredSize(new Dimension(78, 50));
- button1 = new JButton("1");
- button1.setPreferredSize(new Dimension(78, 50));
- button2 = new JButton("2");
- button2.setPreferredSize(new Dimension(78, 50));
- button3 = new JButton("3");
- button3.setPreferredSize(new Dimension(78, 50));
- button4 = new JButton("4");
- button4.setPreferredSize(new Dimension(78, 50));
- button5 = new JButton("5");
- button5.setPreferredSize(new Dimension(78, 50));
- button6 = new JButton("6");
- button6.setPreferredSize(new Dimension(78, 50));
- button7 = new JButton("7");
- button7.setPreferredSize(new Dimension(78, 50));
- button8 = new JButton("8");
- button8.setPreferredSize(new Dimension(78, 50));
- button9 = new JButton("9");
- button9.setPreferredSize(new Dimension(78, 50));
- buttonforsum = new JButton("+");
- buttonforsum.setPreferredSize(new Dimension(78, 50));
- buttoncus = new JButton("C");
- buttoncus.setPreferredSize(new Dimension(78, 50));
- JPanel ln = new JPanel();
- utah = new DefaultTableModel(kolomNama, 0);
- tabel = new JTable(utah);
- tabel.setTableHeader(null);
- tabel.setShowGrid(false);
- tabel.setDefaultEditor(Object.class, null);
- tabel.getColumnModel().getColumn(2).setMinWidth(0);
- tabel.getColumnModel().getColumn(2).setMaxWidth(0);
- tabel.getColumnModel().getColumn(2).setWidth(0);
- tabel.getColumnModel().getColumn(3).setMinWidth(0);
- tabel.getColumnModel().getColumn(3).setMaxWidth(0);
- tabel.getColumnModel().getColumn(3).setWidth(0);
- tabel.getColumnModel().getColumn(4).setMinWidth(0);
- tabel.getColumnModel().getColumn(4).setMaxWidth(0);
- tabel.getColumnModel().getColumn(4).setWidth(0);
- tabel.getColumnModel().getColumn(5).setMinWidth(0);
- tabel.getColumnModel().getColumn(5).setMaxWidth(0);
- tabel.getColumnModel().getColumn(5).setWidth(0);
- tabel.addMouseListener(new MouseAdapter()
- {
- public void mouseClicked(MouseEvent event)
- {
- if (!edit)
- {
- int row = tabel.rowAtPoint(event.getPoint());
- int col = 1;
- int te = 0;
- y = tabel.getValueAt(row, col).toString();
- te = (Integer.parseInt(y) + Integer.parseInt(pos));
- pos = Integer.toString(te);
- TblTotal.setText("Total Rp. " + pos);
- utah.setValueAt(Integer.parseInt
- (tabel.getValueAt(row, 5).toString()) + 1, row, 5);
- tabel.setModel(utah);
- }
- else
- {
- makeItemMenu("edit", tabel.rowAtPoint(event.getPoint()));
- }
- }
- }
- );
- x = new JScrollPane(tabel);
- x.setPreferredSize(new Dimension(240, 150));
- iconcus.addActionListener(menu);
- iconbeli.addActionListener(menu);
- tombolbarang.addActionListener(menu);
- tombolcus.addActionListener(menu);
- buttoncreate.addActionListener(menu);
- buttondone.addActionListener(menu);
- button9.addActionListener(menu);
- button8.addActionListener(menu);
- button7.addActionListener(menu);
- button6.addActionListener(menu);
- button5.addActionListener(menu);
- button4.addActionListener(menu);
- button3.addActionListener(menu);
- button2.addActionListener(menu);
- button1.addActionListener(menu);
- button0.addActionListener(menu);
- buttoncus.addActionListener(menu);
- buttonforsum.addActionListener(menu);
- ln.add(TblTotal);
- ln.add(tombolbarang);
- ln.add(tombolcus);
- ln.add(iconcari);
- ln.add(TblCari);
- ln.add(iconcus);
- ln.add(buttoncreate);
- ln.add(x);
- ln.add(buttondone);
- ln.add(iconbeli);
- ln.add(TblCus);
- ln.add(button1);
- ln.add(button2);
- ln.add(button3);
- ln.add(button4);
- ln.add(button5);
- ln.add(button6);
- ln.add(button7);
- ln.add(button8);
- ln.add(button9);
- ln.add(buttoncus);
- ln.add(button0);
- ln.add(buttonforsum);
- frame.add(ln);
- frame.setSize(280, 500);
- menu.startLibrary();
- frame.show();
- }
- public static void makeItemMenu(String buffer, int row)
- {
- if(buffer.compareTo("new") == 0)
- {
- Custom = false;
- }
- else
- {
- Custom = true;
- }
- if(!Custom)
- {
- itemframe = new JFrame("Input Barang Baru");
- }
- else
- {
- itemframe = new JFrame("Edit Item");
- }
- LblNama = new JTextField(24);
- LblHarga = new JTextField(24);
- LblKategori = new JTextField(24);
- LblIDBarang = new JTextField(24);
- Lbldeskripsi = new JTextField(24);
- if(Custom)
- {
- LblNama.setText(tabel.getValueAt(row, 0).toString());
- LblHarga.setText(tabel.getValueAt(row, 1).toString());
- LblKategori.setText(tabel.getValueAt(row, 2).toString());
- LblIDBarang.setText(tabel.getValueAt(row, 3).toString());
- Lbldeskripsi.setText(tabel.getValueAt(row, 4).toString());
- }
- else
- {
- LblNama.setText("Nama Barang");
- LblHarga.setText("Harga");
- LblKategori.setText("Kategori");
- LblIDBarang.setText("IDBarang");
- Lbldeskripsi.setText("Deskripsi");
- }
- LblNama.addMouseListener(new MouseAdapter()
- {
- public void mouseClicked(MouseEvent e)
- {
- if(LblNama.getText().equals("Item Name"))
- {
- LblNama.setText("");
- }
- }
- }
- );
- LblKategori.addMouseListener(new MouseAdapter()
- {
- public void mouseClicked(MouseEvent e)
- {
- if(LblKategori.getText().equals("Category"))
- {
- LblKategori.setText("");
- }
- }
- }
- );
- LblHarga.addMouseListener(new MouseAdapter()
- {
- public void mouseClicked(MouseEvent e)
- {
- if(LblHarga.getText().equals("Price"))
- {
- LblHarga.setText("");
- }
- }
- }
- );
- LblIDBarang.addMouseListener(new MouseAdapter()
- {
- public void mouseClicked(MouseEvent e)
- {
- if(LblIDBarang.getText().equals("SKU"))
- {
- LblIDBarang.setText("");
- }
- }
- }
- );
- Lbldeskripsi.addMouseListener(new MouseAdapter()
- {
- public void mouseClicked(MouseEvent e)
- {
- if(Lbldeskripsi.getText().equals("Description"))
- {
- Lbldeskripsi.setText("");
- }
- }
- }
- );
- buttonesc = new JButton("X");
- buttonesc.setPreferredSize(new Dimension(50, 50));
- buttonsave = new JButton("SAVE");
- buttonsave.setPreferredSize(new Dimension(190, 50));
- buttondelete = new JButton("DELETE");
- buttondelete.setPreferredSize(new Dimension(240, 50));
- JPanel itembenchmark = new JPanel();
- buttonsave.addActionListener(menu);
- buttonesc.addActionListener(menu);
- buttondelete.addActionListener(menu);
- itembenchmark.add(LblNama);
- itembenchmark.add(LblKategori);
- itembenchmark.add(LblHarga);
- itembenchmark.add(LblIDBarang);
- itembenchmark.add(Lbldeskripsi);
- itembenchmark.add(buttonesc);
- itembenchmark.add(buttonsave);
- if(Custom)
- {
- itembenchmark.add(buttondelete);
- }
- itemframe.add(itembenchmark);
- itemframe.setSize(300, 500);
- itemframe.show();
- }
- public static void makePurchaseMenu()
- {
- int total = 0;
- Object[] object = new Object[4];
- byrframe = new JFrame("Bayar");
- byr = true;
- currentsale = new JLabel("CURRENT SALE");
- LblByrTotal = new JTextField(24);
- LblByrTotal.setEditable(false);
- LblByrTotal.setText("Total Rp. " + pos);
- byrmodel = new DefaultTableModel(byrkolomNama, 0);
- for(int i = 0; i < tabel.getRowCount(); i++)
- {
- if(Integer.parseInt(tabel.getValueAt(i, 5).toString()) > 0)
- {
- object[0] = tabel.getValueAt(i, 0).toString();
- object[1] = ("x" + tabel.getValueAt(i, 5).toString());
- object[2] =
- Integer.parseInt(tabel.getValueAt(i, 1).toString()) *
- Integer.parseInt(tabel.getValueAt(i, 5).toString());
- object[3] = "X";
- total = total +
- Integer.parseInt(tabel.getValueAt(i, 1).toString()) *
- Integer.parseInt(tabel.getValueAt(i, 5).toString());
- byrmodel.addRow(object);
- }
- }
- if (total < Integer.parseInt(pos))
- {
- object[0] = "Custom";
- object[1] = "";
- object[2] = Integer.parseInt(pos) - total;
- object[3] = "X";
- byrmodel.addRow(object);
- }
- byrtable = new JTable(byrmodel);
- byrtable.getColumnModel().getColumn(3).setMinWidth(11);
- byrtable.getColumnModel().getColumn(3).setMaxWidth(11);
- byrtable.getColumnModel().getColumn(3).setWidth(11);
- byrtable.setTableHeader(null);
- byrtable.setShowGrid(false);
- byrtable.setDefaultEditor(Object.class, null);
- byrtable.addMouseListener(new MouseAdapter()
- {
- public void mouseClicked(MouseEvent event)
- {
- int col = byrtable.columnAtPoint(event.getPoint());
- int row = byrtable.rowAtPoint(event.getPoint());
- if (col == 3)
- {
- int te = 0;
- y = byrtable.getValueAt(row, 2).toString();
- te = (Integer.parseInt(pos) - Integer.parseInt(y));
- pos = Integer.toString(te);
- LblByrTotal.setText("Total Rp. " + pos);
- TblTotal.setText("Total Rp. " + pos);
- for (int i = 0; i < utah.getRowCount(); i++)
- {
- if(utah.getValueAt(i, 0) ==
- byrtable.getValueAt(row, 0))
- {
- utah.setValueAt(0, i, 5);
- }
- }
- int numberOFRows = byrtable.getSelectedRows().length;
- for(int i = 0; i < numberOFRows ; i++)
- {
- byrmodel.removeRow(byrtable.getSelectedRow());
- }
- byrtable.setModel(byrmodel);
- }
- }
- }
- );
- byrx = new JScrollPane(byrtable);
- byrx.setPreferredSize(new Dimension(240, 150));
- tombolescbyr = new JButton("X");
- tombolescbyr.setPreferredSize(new Dimension(50, 50));
- tombolclear = new JButton("Clear Sale");
- tombolclear.setPreferredSize(new Dimension(190, 50));
- JPanel byrbenchmark = new JPanel();
- tombolclear.addActionListener(menu);
- tombolescbyr.addActionListener(menu);
- byrbenchmark.add(currentsale);
- byrbenchmark.add(byrx);
- byrbenchmark.add(LblByrTotal);
- byrbenchmark.add(tombolescbyr);
- byrbenchmark.add(tombolclear);
- byrframe.add(byrbenchmark);
- byrframe.setSize(300, 500);
- byrframe.show();
- }
- public static void startLibrary()
- {
- tombolbarang.setEnabled(false);
- tombolcus.setEnabled(true);
- iconcari.setVisible(true);
- TblCari.setVisible(true);
- TblCus.setVisible(false);
- iconcus.setVisible(true);
- buttoncreate.setVisible(false);
- x.setVisible(true);
- buttondone.setVisible(false);
- iconbeli.setVisible(true);
- button9.setVisible(false);
- button8.setVisible(false);
- button7.setVisible(false);
- button6.setVisible(false);
- button5.setVisible(false);
- button4.setVisible(false);
- button3.setVisible(false);
- button2.setVisible(false);
- button1.setVisible(false);
- button0.setVisible(false);
- buttoncus.setVisible(false);
- buttonforsum.setVisible(false);
- }
- public static void starteditLibrary()
- {
- tombolbarang.setEnabled(false);
- tombolcus.setEnabled(false);
- TblCus.setVisible(false);
- iconcus.setVisible(false);
- buttoncreate.setVisible(true);
- iconbeli.setVisible(false);
- buttondone.setVisible(true);
- }
- public static void startCustom()
- {
- y = "";
- TblCus.setText("Rp. 0");
- tombolbarang.setEnabled(true);
- tombolcus.setEnabled(false);
- TblCari.setVisible(false);
- TblCus.setVisible(true);
- iconcari.setVisible(false);
- iconcus.setVisible(false);
- buttoncreate.setVisible(false);
- x.setVisible(false);
- iconbeli.setVisible(false);
- button9.setVisible(true);
- button8.setVisible(true);
- button7.setVisible(true);
- button6.setVisible(true);
- button5.setVisible(true);
- button4.setVisible(true);
- button3.setVisible(true);
- button2.setVisible(true);
- button1.setVisible(true);
- button0.setVisible(true);
- buttoncus.setVisible(true);
- buttonforsum.setVisible(true);
- }
- public void actionPerformed(ActionEvent event)
- {
- String s = event.getActionCommand();
- if ((s.charAt(0) >= '0' && s.charAt(0) <= '9'))
- {
- // if operand is present then add to second no
- y = y + s;
- // set the value of text
- TblCus.setText("Rp. " + y);
- }
- else if (s.equals("C"))
- {
- y = "";
- // set the value of text
- TblCus.setText("Rp. 0");
- }
- else if (s.charAt(0) == '+')
- {
- int te = 0;
- if(y == "")
- {
- y = "0";
- }
- te = (Integer.parseInt(y) + Integer.parseInt(pos));
- // convert it to string
- pos = Integer.toString(te);
- y = "";
- TblCus.setText("Rp. 0");
- TblTotal.setText("Total Rp. " + pos);
- }
- else if (s.equals("Barang"))
- {
- startLibrary();
- }
- else if (s.equals("Custom"))
- {
- startCustom();
- }
- else if (s.equals("edit"))
- {
- starteditLibrary();
- edit = true;
- }
- else if (s.equals("Bayar"))
- {
- makePurchaseMenu();
- frame.dispose();
- }
- else if (s.equals("$ELESAI"))
- {
- startLibrary();
- edit = false;
- }
- else if (s.equals("Input Barang Baru"))
- {
- makeItemMenu("new", 0);
- }
- else if (s.equals("SAVE"))
- {
- Object[] row = new Object[6];
- row[0] = (String)LblNama.getText();
- row[1] = LblHarga.getText();
- row[2] = (String)LblKategori.getText();
- row[3] = (String)LblIDBarang.getText();
- row[4] = (String)Lbldeskripsi.getText();
- row[5] = 0;
- utah.addRow(row);
- tabel.setModel(utah);
- if(Custom)
- {
- int numberOFRows = tabel.getSelectedRows().length;
- for(int i = 0; i < numberOFRows ; i++)
- {
- utah.removeRow(tabel.getSelectedRow());
- }
- }
- itemframe.dispose();
- }
- else if (s.equals("X"))
- {
- if(byr == true)
- {
- byrframe.dispose();
- frame.show();
- }
- else
- {
- itemframe.dispose();
- }
- }
- else if (s.equals("DELETE"))
- {
- int numberOFRows = tabel.getSelectedRows().length;
- for(int i = 0; i < numberOFRows ; i++)
- {
- utah.removeRow(tabel.getSelectedRow());
- }
- itemframe.dispose();
- }
- else if (s.equals("Hapus Riwayat"))
- {
- TblCus.setText("Rp. 0");
- TblTotal.setText("Total Rp. 0");
- LblByrTotal.setText("Total Rp. 0");
- y = "";
- pos = "0";
- for (int i = byrmodel.getRowCount() - 1; i >= 0; i--)
- {
- byrmodel.removeRow(i);
- }
- byrtable.setModel(byrmodel);
- for (int i = 0; i < utah.getRowCount(); i++)
- {
- utah.setValueAt(0, i, 5);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement