-
Notifications
You must be signed in to change notification settings - Fork 2
/
InventoryPanel.java
96 lines (77 loc) · 3.16 KB
/
InventoryPanel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import java.sql.*;
import java.util.ArrayList;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.LineBorder;
import java.awt.event.*;
/**
* @category Manager Side
* @summary Creates a table containing all inventory item ids, names, and current amounts. Also contains
* function to update the quantity of an item, insert a new item, or remove an item from the menu.
*/
public class InventoryPanel extends JPanel {
protected JTextArea textArea;
private final static String newline = "\n";
private static ArrayList<Functions.InventoryItem> inventoryItems;
/**
* @throws SQLException
*/
public InventoryPanel() throws SQLException {
super(new GridBagLayout());
JButton updateInv = new JButton("Update Inventory");
updateInv.setPreferredSize(new Dimension(200, 50));
updateInv.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try{
String itemName = JOptionPane.showInputDialog("Ingredient name:");
String itemType = "1-1-1111";//JOptionPane.showInputDialog("expDate");
String itemCost = JOptionPane.showInputDialog("Amount");
Integer xx = Integer.parseInt(itemCost);
Functions.addBatch(itemName, xx, itemType);
InventoryPanel yy = new InventoryPanel();
Main.inventoryPanel = yy;
Main.cards.add(yy, "inventoryPanel");
Main.inventoryPanel.revalidate();
Main.cardlayout.show(Main.cards, "inventoryPanel");
}
catch(Exception x) {
System.out.println(x.getMessage());
}
}
});
JButton jb = new JButton("GO BACK");
jb.setPreferredSize(new Dimension(200, 50));
jb.setBackground(Color.GRAY);
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
//go back
Main.cardlayout.show(Main.cards, "managerPanel");
}
});
add(updateInv);
add(jb);
String[] columnNames = {"id",
"name",
"quantity"};
String[] newItem;
inventoryItems = Functions.getInventoryItems();
String[][] data = new String[inventoryItems.size()][3];
int i = 0;
for (Functions.InventoryItem item : inventoryItems) {
newItem = new String[3];
newItem[0] = "" + item.id;
newItem[1] = item.name;
newItem[2] = "" + item.quantity;
data[i] = newItem;
i++;
}
final JTable table = new JTable(data, columnNames);
table.setRowHeight(30);
table.setPreferredScrollableViewportSize(table.getPreferredSize());
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setPreferredSize(new Dimension(500, 500));
//Add the scroll pane to this panel.
add(scrollPane);
}
}