package panels; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.HashMap; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; import frames.MainFrame; import resources.Customer; //------------------------------------------------------------------------- // public class ShowHistoryPanel extends JPanel { // model private HashMap<Integer, Customer> customerTable; // table private JTable panelTable; private DefaultTableModel panelTableModel; private String[] columnNames = { "name", "total", "points" }; // buttons private JButton addButton; private JButton modifyButton; private JButton removeButton; // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- // constructor // ------------------------------------------------------------------------- // public ShowHistoryPanel() { super(new BorderLayout()); // initialize model customerTable = new HashMap<Integer, Customer>(); // initialize table panelTableModel = new DefaultTableModel(columnNames, 0); panelTable = new JTable(panelTableModel); // deny to edit cell panelTable.setDefaultEditor(Object.class, null); // add buttons addButton = new JButton("Add"); modifyButton = new JButton("Modify"); removeButton = new JButton("Remove"); // add listener // todo: add back to main JPanel buttonPanel = new JPanel(); buttonPanel.add(addButton); buttonPanel.add(modifyButton); buttonPanel.add(removeButton); add(buttonPanel, BorderLayout.SOUTH); // add scroll menu JScrollPane listScrollPane = new JScrollPane(panelTable); add(listScrollPane, BorderLayout.NORTH); } // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- // private // ------------------------------------------------------------------------- // private void transitionToHistory(MainFrame mainFrame) { mainFrame.showHistoryPanel(this); } // ------------------------------------------------------------------------- // private Object[] generateCustomerRow(String name) { Customer customer = new Customer(name + panelTableModel.getRowCount()); Object[] data = { customer.getName(), customer.getPOS().getTotal(), customer.getPOS().getPoints() }; return data; } }