-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventory.java
More file actions
142 lines (125 loc) · 5 KB
/
Inventory.java
File metadata and controls
142 lines (125 loc) · 5 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
public class Inventory extends JPanel {
public JTextField textField;
public JTextField quantField;
protected ArrayList<String> items = new ArrayList<>();
protected ArrayList<Integer> amounts = new ArrayList<>();
public JButton button;
public Connect connect = new Connect();
Inventory() {
GridBagLayout layout = new GridBagLayout();
setLayout(layout);
GridBagConstraints constraints = new GridBagConstraints();
constraints.insets = new Insets(5, 5, 5, 5);
constraints.gridx = 0;
constraints.gridy = 0;
JButton viewList = new JButton();
try {
viewList.setIcon(new ImageIcon(ImageIO.read(new File("listbutton3.png"))));
} catch (IOException e) {
e.printStackTrace();
}
add(viewList, constraints);
viewList.addActionListener(e -> {
if(items.isEmpty() || amounts.isEmpty()) {
JOptionPane.showMessageDialog(null, "List is empty");
}
else {
ShowList showList = new ShowList();
showList.listView(items, amounts);
}
});
constraints.gridx = 1;
constraints.gridy = 0;
JLabel title = new JLabel("Inventory System");
//title.setForeground(Color.BLUE);
title.setFont(new Font("Arial", Font.BOLD, 24));
add(title, constraints);
constraints.gridx = 0;
constraints.gridy = 1;
JLabel label = new JLabel("Item number");
label.setFont(new Font("Arial", Font.BOLD, 16));
add(label, constraints);
constraints.gridx = 1;
constraints.gridy = 1;
textField = new JTextField(20);
add(textField, constraints);
constraints.gridx = 0;
constraints.gridy = 3;
JLabel label1 = new JLabel("Quantity");
label1.setFont(new Font("Arial", Font.BOLD, 16));
add(label1, constraints);
constraints.gridx = 1;
constraints.gridy = 3;
quantField = new JTextField(20);
add(quantField, constraints);
constraints.gridx = 1;
constraints.gridy = 4;
button = new JButton("Add to List");
add(button, constraints);
button.addActionListener(e -> {
int inum = Integer.parseInt(quantField.getText());
String text = textField.getText();
addToCart(text, inum);
});
constraints.gridx = 1;
constraints.gridy = 5;
JButton confirmButton = new JButton("Confirm Order");
add(confirmButton, constraints);
confirmButton.addActionListener(e -> confirmPurchase());
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
int w = getWidth();
int h = getHeight();
Color color1 = Color.LIGHT_GRAY;
Color color2 = Color.DARK_GRAY;
GradientPaint gp = new GradientPaint(0, 0, color1, 0, h, color2);
g2d.setPaint(gp);
g2d.fillRect(0, 0, w, h);
}
public void clearList() {
items.clear();
amounts.clear();
items.trimToSize();
amounts.trimToSize();
System.out.println(items);
System.out.println(amounts);
}
//adds item to lists
public void addToCart(String item, int quantity) {
items.add(item);
amounts.add(quantity);
}
public void confirmPurchase() {
for (int i = 0; i < items.size(); i++) {
String itemName = items.get(i);
int conversion = Integer.parseInt(itemName);
int itemQuantity = amounts.get(i);
connect.transaction(conversion, itemQuantity, false);
}
clearList();
}
/**public String getTime() {
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
return formatter.format(date);
}**/
public static void main(String[] args) {
JFrame frame = new JFrame("Inventory");
frame.setJMenuBar(new MenuDriver());
frame.setSize(700, 500);
frame.add(new Inventory());
Image icon = Toolkit.getDefaultToolkit().getImage("Inventory.png");
frame.setIconImage(icon);
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
}