-
Notifications
You must be signed in to change notification settings - Fork 0
/
StoreInfo.java
165 lines (134 loc) · 4.18 KB
/
StoreInfo.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.table.*;
public class StoreInfo extends JFrame{
private JButton stock = new JButton("Stock");
private JButton search = new JButton("Search/Update");
private JButton Addfruit = new JButton("Add Fruit");
private JButton back = new JButton("Back");
private JPanel pcenter = new JPanel();
private JPanel pnorth = new JPanel();
private JTextArea data = new JTextArea();
private JScrollPane textScro = new JScrollPane(data);
private FruitDB fruit = new FruitDB();
public StoreInfo(){
setSize(500,300);
pnorth.setLayout(new GridLayout(1,4));
pnorth.add(stock);
pnorth.add(search);
pnorth.add(Addfruit);
pnorth.add(back);
add(pnorth, BorderLayout.NORTH);
add(textScro, BorderLayout.CENTER);
back.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dispose();
}
});
stock.addActionListener(new stockWinAction());
search.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
SearchFruit mw = new SearchFruit();
mw.setTitle("Search/Update Store");
mw.setAlwaysOnTop(true);
mw.setUndecorated(true);
mw.setLocationRelativeTo(null);
mw.pack();
mw.setVisible(true);
}
});
Addfruit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
addToStore mw = new addToStore();
mw.setTitle("Add Fruit");
mw.setAlwaysOnTop(true);
mw.setUndecorated(true);
mw.setLocationRelativeTo(null);
mw.pack();
mw.setVisible(true);
}
});
}
class stockWinAction implements ActionListener{
public void actionPerformed(ActionEvent e){
ResultSet res = fruit.getStroeFruits();
try{
stock.setText("Refresh");
data.setText("Fruit\tQuntity\tPrice SR");
while(res.next()){
data.append("\n---------------------------------");
data.append("\n" + res.getString(1) + " \t"
+ res.getInt(2) + " \t" + res.getDouble(3));
}
}catch(Exception p){
System.out.println(p.getMessage());
}
}
}
private class addToStore extends JFrame{
private JButton add = new JButton("Add to Stock");
private JButton backb = new JButton("Back");
private JTextField namet = new JTextField();
private JTextField pricet = new JTextField();
private JTextField quntt = new JTextField();
private JLabel pricel = new JLabel("Price: ");
private JLabel quntl = new JLabel("Quntity: ");
private JLabel namel = new JLabel("Fruit: ");
private JLabel emp = new JLabel();
private JPanel pcenter = new JPanel();
private JPanel psouth = new JPanel();
public addToStore(){
pcenter.setLayout(new GridLayout(3, 2));
pcenter.add(namel);
pcenter.add(namet);
pcenter.add(pricel);
pcenter.add(pricet);
pcenter.add(quntl);
pcenter.add(quntt);
add(pcenter, BorderLayout.CENTER);
psouth.setLayout(new GridLayout(1, 3));
psouth.add(add);
psouth.add(emp);
psouth.add(backb);
add(psouth, BorderLayout.SOUTH);
backb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dispose();
}
});
add.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String name = namet.getText();
if(!fruit.isInStore(name)){
int qu = Integer.parseInt(quntt.getText());
double pr = Double.parseDouble(pricet.getText());
fruit.newFruit(name, qu, pr);
quntt.setText("");
namet.setText("");
pricet.setText("");
JDialog jdia = new JDialog();
jdia.setAlwaysOnTop(true);
JOptionPane.showMessageDialog(jdia,
"Fruit: " + name + " add to stock\nwith price: "
+ pr + " SR and Quntitey: " + qu,
"Fruit Added!",
JOptionPane.WARNING_MESSAGE);
}else{
quntt.setText("");
namet.setText("");
pricet.setText("");
JDialog jdia = new JDialog();
jdia.setAlwaysOnTop(true);
JOptionPane.showMessageDialog(jdia,
name + " is in the Stock",
"Furit in the Stock!",
JOptionPane.WARNING_MESSAGE);
}
}
});
}
}
}