-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPurchasingFram.java
More file actions
288 lines (243 loc) · 14.2 KB
/
PurchasingFram.java
File metadata and controls
288 lines (243 loc) · 14.2 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package naeemmohammadprogrammingckpt3;
import java.util.InputMismatchException;
import javax.swing.JOptionPane;
/**
* This class represents PurchasingFram as the second Jframe which shows user(s)
* the bookstore inventory and completes their purchase(s)
*
* @author Mohammad Naeem
*/
public class PurchasingFram extends javax.swing.JFrame {
private BookStore myModel;
private double totalCost;
/**
* Creates new form MainMenuFram
*
* @param myModel
*/
public PurchasingFram(BookStore myModel) {
this.myModel = myModel;
initComponents();
purchaseMessage.setVisible(false);
continueButton.setVisible(false);
bookArea.setText("");
cdArea.setText("");
dvdArea.setText("");
for (Product i : myModel.getInventory()) {
if (i instanceof Book) {
String str = new String(i.getProductID() + "- " + " Book: " + i.getProductName() + ", " + "by author:" + " "
+ ((Book) i).getBookAuthor() + ", quantity = " + i.getNumInStock() + ", Price: $" + i.getProductCost());
bookArea.append(str + "\n");
}
if (i instanceof CD) {
String str = new String(i.getProductID() + "- " + " CD: " + i.getProductName() + ", " + "by artist:" + " "
+ ((CD) i).getCDArtist() + ", quantity = " + i.getNumInStock() + ", Price: $" + i.getProductCost());
cdArea.append(str + "\n");
}
if (i instanceof DVD) {
String str = new String(i.getProductID() + "- " + " DVD: " + i.getProductName() + ", " + "by producer:" + " "
+ ((DVD) i).getDVDProducer() + ", quantity = " + i.getNumInStock() + ", Price: $" + i.getProductCost());
dvdArea.append(str + "\n");
}
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jButton1 = new javax.swing.JButton();
PurchasingFramTitle = new javax.swing.JLabel();
bookTitle = new javax.swing.JLabel();
cdTitle = new javax.swing.JLabel();
dvdTitle = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
bookArea = new javax.swing.JTextArea();
jScrollPane2 = new javax.swing.JScrollPane();
cdArea = new javax.swing.JTextArea();
jScrollPane3 = new javax.swing.JScrollPane();
dvdArea = new javax.swing.JTextArea();
idInputCommand = new javax.swing.JLabel();
idInput = new javax.swing.JTextField();
purchaseMessage = new javax.swing.JLabel();
continueButton = new javax.swing.JButton();
returnButton = new javax.swing.JButton();
totalCostMessage = new javax.swing.JLabel();
jMenuItem1.setText("jMenuItem1");
jMenuItem2.setText("jMenuItem2");
jButton1.setText("jButton1");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
PurchasingFramTitle.setFont(new java.awt.Font("Sitka Heading", 3, 48)); // NOI18N
PurchasingFramTitle.setText("Checkout");
bookTitle.setFont(new java.awt.Font("Sitka Subheading", 3, 24)); // NOI18N
bookTitle.setForeground(new java.awt.Color(0, 153, 102));
bookTitle.setText("Book");
cdTitle.setFont(new java.awt.Font("Sitka Subheading", 3, 24)); // NOI18N
cdTitle.setForeground(new java.awt.Color(0, 153, 102));
cdTitle.setText("CD");
dvdTitle.setFont(new java.awt.Font("Sitka Subheading", 3, 24)); // NOI18N
dvdTitle.setForeground(new java.awt.Color(0, 153, 102));
dvdTitle.setText("DVD");
bookArea.setColumns(20);
bookArea.setFont(new java.awt.Font("Sitka Text", 1, 16)); // NOI18N
bookArea.setRows(5);
jScrollPane1.setViewportView(bookArea);
cdArea.setColumns(20);
cdArea.setFont(new java.awt.Font("Sitka Text", 1, 16)); // NOI18N
cdArea.setRows(5);
jScrollPane2.setViewportView(cdArea);
dvdArea.setColumns(20);
dvdArea.setFont(new java.awt.Font("Sitka Text", 1, 16)); // NOI18N
dvdArea.setRows(5);
jScrollPane3.setViewportView(dvdArea);
idInputCommand.setFont(new java.awt.Font("Sitka Subheading", 1, 16)); // NOI18N
idInputCommand.setText("Type in the ID#:");
idInput.setFont(new java.awt.Font("Sitka Text", 1, 16)); // NOI18N
idInput.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
idInputActionPerformed(evt);
}
});
continueButton.setFont(new java.awt.Font("Sitka Subheading", 3, 13)); // NOI18N
continueButton.setForeground(new java.awt.Color(0, 153, 51));
continueButton.setText(">>> Continue Shopping <<<");
continueButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
continueButtonActionPerformed(evt);
}
});
returnButton.setFont(new java.awt.Font("Sitka Subheading", 3, 12)); // NOI18N
returnButton.setForeground(new java.awt.Color(0, 153, 51));
returnButton.setText(">>> Return to Main Menu <<<");
returnButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
returnButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGap(40, 40, 40)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(460, 460, 460)
.addComponent(PurchasingFramTitle))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1066, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cdTitle)
.addComponent(bookTitle)))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(dvdTitle)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 1066, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 1066, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(idInputCommand, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(idInput, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(purchaseMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 508, Short.MAX_VALUE)
.addComponent(totalCostMessage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(95, 95, 95))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(continueButton, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addComponent(returnButton)))))
.addContainerGap(485, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(PurchasingFramTitle)
.addGap(41, 41, 41)
.addComponent(bookTitle)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(cdTitle)
.addGap(16, 16, 16)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(dvdTitle)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(idInputCommand, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(idInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(purchaseMessage))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(returnButton)
.addComponent(continueButton)
.addComponent(totalCostMessage))
.addGap(26, 26, 26))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void idInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_idInputActionPerformed
// TODO add your handling code here:
purchaseMessage.setVisible(true);
continueButton.setVisible(true);
int id = Integer.parseInt(idInput.getText());
Product soldProduct = myModel.getProduct(id);
purchaseMessage.setText("You have bought the product: " + soldProduct.getProductName() + " for $" + soldProduct.getProductCost());
totalCost += soldProduct.getProductCost();
totalCostMessage.setText("Total Cost is $" + totalCost);
}//GEN-LAST:event_idInputActionPerformed
private void continueButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_continueButtonActionPerformed
// TODO add your handling code here:
idInput.setText("");
purchaseMessage.setText("");
continueButton.setVisible(false);
}//GEN-LAST:event_continueButtonActionPerformed
private void returnButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_returnButtonActionPerformed
// TODO add your handling code here:
this.dispose();
MainMenuFram mmf = new MainMenuFram(myModel);
mmf.setVisible(true);
}//GEN-LAST:event_returnButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel PurchasingFramTitle;
private javax.swing.JTextArea bookArea;
private javax.swing.JLabel bookTitle;
private javax.swing.JTextArea cdArea;
private javax.swing.JLabel cdTitle;
private javax.swing.JButton continueButton;
private javax.swing.JTextArea dvdArea;
private javax.swing.JLabel dvdTitle;
private javax.swing.JTextField idInput;
private javax.swing.JLabel idInputCommand;
private javax.swing.JButton jButton1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JLabel purchaseMessage;
private javax.swing.JButton returnButton;
private javax.swing.JLabel totalCostMessage;
// End of variables declaration//GEN-END:variables
}