Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.

java
1 /*
2 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3 * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
4 */
5 package screens;
6
7 import g12_skypat.*;
8 import java.awt.Image;
9 import java.sql.*;
10 import java.text.DecimalFormat;
11 import javax.swing.ImageIcon;
12
13 /**
14 *
15 * @author User
16 */
17 public class POS extends javax.swing.JFrame {
18
19 /**
20 * Creates new form POS
21 */
22 private Database db = new Database();
23 private Receipt toReceipt = new Receipt();
24
25 private ResultSet resultset;
26
27 private boolean isInvalid = false;
28 private boolean isPrinted = false;
29
30
31
32
33
1.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
34
35 public POS() {
36
37 initComponents();
38
39 convertLOGO();
40
41 setTxtAreaProducts();
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
2.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
67
68 /**
69 * This method is called from within the constructor to initialize the form.
70 * WARNING: Do NOT modify this code. The content of this method is always
71 * regenerated by the Form Editor.
72 */
73 @SuppressWarnings("unchecked")
74 // <editor-fold defaultstate="collapsed" desc="Generated Code">
75 private void initComponents() {
76
77 panelPOS = new javax.swing.JPanel();
78 jPanel2 = new javax.swing.JPanel();
79 jScrollPane1 = new javax.swing.JScrollPane();
80 txtareaProducts = new javax.swing.JTextArea();
81 jPanel3 = new javax.swing.JPanel();
82 btnZero = new javax.swing.JButton();
83 btnOne = new javax.swing.JButton();
84 btnTwo = new javax.swing.JButton();
85 btnThree = new javax.swing.JButton();
86 btnFour = new javax.swing.JButton();
87 btnFive = new javax.swing.JButton();
88 btnSix = new javax.swing.JButton();
89 btnSeven = new javax.swing.JButton();
90 btnEight = new javax.swing.JButton();
91 btnNine = new javax.swing.JButton();
92 btnDel = new javax.swing.JButton();
93 btnClear = new javax.swing.JButton();
94 jPanel4 = new javax.swing.JPanel();
95 txtfieldTotalCost = new javax.swing.JTextField();
96 jPanel5 = new javax.swing.JPanel();
97 txtfieldProductID = new javax.swing.JTextField();
98 lblSPAR_LOGO = new javax.swing.JLabel();
99 jPanel6 = new javax.swing.JPanel();
3.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
100 btnPay = new javax.swing.JButton();
101 btnAdmin = new javax.swing.JButton();
102 btnPrint = new javax.swing.JButton();
103 btnNewOrder = new javax.swing.JButton();
104
105 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
106
107 panelPOS.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
108 panelPOS.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
109
110 txtareaProducts.setEditable(false);
111 txtareaProducts.setFont(new java.awt.Font("Courier New", 1, 20)); // NOI18N
112 jScrollPane1.setViewportView(txtareaProducts);
113
114 javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
115 jPanel2.setLayout(jPanel2Layout);
116 jPanel2Layout.setHorizontalGroup(
117 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
118 .addGroup(jPanel2Layout.createSequentialGroup()
119 .addContainerGap()
120 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 381, Short.MAX_VALUE))
121 );
122 jPanel2Layout.setVerticalGroup(
123 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
124 .addGroup(jPanel2Layout.createSequentialGroup()
125 .addContainerGap()
126 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 478, Short.MAX_VALUE)
127 .addContainerGap())
128 );
129
130 panelPOS.add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 123, 391, 500));
131
132 btnZero.setText("0");
4.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
133 btnZero.addActionListener(new java.awt.event.ActionListener() {
134 public void actionPerformed(java.awt.event.ActionEvent evt) {
135 btnZeroActionPerformed(evt);
136 }
137 });
138
139 btnOne.setText("1");
140 btnOne.addActionListener(new java.awt.event.ActionListener() {
141 public void actionPerformed(java.awt.event.ActionEvent evt) {
142 btnOneActionPerformed(evt);
143 }
144 });
145
146 btnTwo.setText("2");
147 btnTwo.addActionListener(new java.awt.event.ActionListener() {
148 public void actionPerformed(java.awt.event.ActionEvent evt) {
149 btnTwoActionPerformed(evt);
150 }
151 });
152
153 btnThree.setText("3");
154 btnThree.addActionListener(new java.awt.event.ActionListener() {
155 public void actionPerformed(java.awt.event.ActionEvent evt) {
156 btnThreeActionPerformed(evt);
157 }
158 });
159
160 btnFour.setText("4");
161 btnFour.addActionListener(new java.awt.event.ActionListener() {
162 public void actionPerformed(java.awt.event.ActionEvent evt) {
163 btnFourActionPerformed(evt);
164 }
165 });
5.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
166
167 btnFive.setText("5");
168 btnFive.addActionListener(new java.awt.event.ActionListener() {
169 public void actionPerformed(java.awt.event.ActionEvent evt) {
170 btnFiveActionPerformed(evt);
171 }
172 });
173
174 btnSix.setText("6");
175 btnSix.addActionListener(new java.awt.event.ActionListener() {
176 public void actionPerformed(java.awt.event.ActionEvent evt) {
177 btnSixActionPerformed(evt);
178 }
179 });
180
181 btnSeven.setText("7");
182 btnSeven.addActionListener(new java.awt.event.ActionListener() {
183 public void actionPerformed(java.awt.event.ActionEvent evt) {
184 btnSevenActionPerformed(evt);
185 }
186 });
187
188 btnEight.setText("8");
189 btnEight.addActionListener(new java.awt.event.ActionListener() {
190 public void actionPerformed(java.awt.event.ActionEvent evt) {
191 btnEightActionPerformed(evt);
192 }
193 });
194
195 btnNine.setText("9");
196 btnNine.addActionListener(new java.awt.event.ActionListener() {
197 public void actionPerformed(java.awt.event.ActionEvent evt) {
198 btnNineActionPerformed(evt);
6.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
199 }
200 });
201
202 btnDel.setText("DELETE");
203 btnDel.addActionListener(new java.awt.event.ActionListener() {
204 public void actionPerformed(java.awt.event.ActionEvent evt) {
205 btnDelActionPerformed(evt);
206 }
207 });
208
209 btnClear.setText("CLEAR");
210 btnClear.addActionListener(new java.awt.event.ActionListener() {
211 public void actionPerformed(java.awt.event.ActionEvent evt) {
212 btnClearActionPerformed(evt);
213 }
214 });
215
216 javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
217 jPanel3.setLayout(jPanel3Layout);
218 jPanel3Layout.setHorizontalGroup(
219 jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
220 .addGroup(jPanel3Layout.createSequentialGroup()
221 .addGap(31, 31, 31)
222 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
223 .addComponent(btnFour, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
224 .addComponent(btnOne, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
225 .addComponent(btnDel, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
226 .addComponent(btnSeven, javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
227 .addGap(18, 18, 18)
228 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
7.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
229 .addComponent(btnTwo, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
230 .addComponent(btnFive, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
231 .addComponent(btnEight, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
232 .addComponent(btnZero, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
233 .addGap(18, 18, 18)
234 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
235 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
236 .addComponent(btnThree, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
237 .addComponent(btnSix, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
238 .addComponent(btnNine, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
239 .addComponent(btnClear, javax.swing.GroupLayout.PREFERRED_SIZE, 87,
javax.swing.GroupLayout.PREFERRED_SIZE))
240 .addContainerGap(12, Short.MAX_VALUE))
241 );
242 jPanel3Layout.setVerticalGroup(
243 jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
244 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
245 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
246 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
247 .addComponent(btnEight, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
248 .addComponent(btnNine, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
249 .addComponent(btnSeven, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
250 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
251 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
252 .addComponent(btnFour, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
253 .addComponent(btnFive, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
8.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
Short.MAX_VALUE)
254 .addComponent(btnSix, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
255 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
256 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
257 .addComponent(btnOne, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
258 .addComponent(btnTwo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
259 .addComponent(btnThree, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
260 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
261 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
262 .addComponent(btnZero, javax.swing.GroupLayout.PREFERRED_SIZE, 83,
javax.swing.GroupLayout.PREFERRED_SIZE)
263 .addComponent(btnDel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
264 .addComponent(btnClear, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
265 .addContainerGap())
266 );
267
268 panelPOS.add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(413, 231, 340, 380));
269
270 txtfieldTotalCost.setEditable(false);
271 txtfieldTotalCost.setBackground(new java.awt.Color(255, 255, 255));
272 txtfieldTotalCost.setFont(new java.awt.Font("Helvetica", 0, 40));
273 txtfieldTotalCost.setFont(new java.awt.Font("Courier New", 0, 40)); // NOI18N
274 txtfieldTotalCost.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
275 txtfieldTotalCost.setText("0.00");
276
277 javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
278 jPanel4.setLayout(jPanel4Layout);
279 jPanel4Layout.setHorizontalGroup(
9.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
280 jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
281 .addGroup(jPanel4Layout.createSequentialGroup()
282 .addContainerGap()
283 .addComponent(txtfieldTotalCost, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
284 .addContainerGap())
285 );
286 jPanel4Layout.setVerticalGroup(
287 jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
288 .addGroup(jPanel4Layout.createSequentialGroup()
289 .addContainerGap()
290 .addComponent(txtfieldTotalCost, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
291 .addContainerGap())
292 );
293
294 panelPOS.add(jPanel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 13, 400, 110));
295
296 txtfieldProductID.setEditable(false);
297 txtfieldProductID.setBackground(new java.awt.Color(255, 255, 255));
298 txtfieldProductID.setColumns(7);
299 txtfieldProductID.setFont(new java.awt.Font("Courier New", 0, 40)); // NOI18N
300 txtfieldProductID.addActionListener(new java.awt.event.ActionListener() {
301 public void actionPerformed(java.awt.event.ActionEvent evt) {
302 txtfieldProductIDActionPerformed(evt);
303 }
304 });
305
306 javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
307 jPanel5.setLayout(jPanel5Layout);
308 jPanel5Layout.setHorizontalGroup(
309 jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
310 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
311 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
312 .addComponent(txtfieldProductID, javax.swing.GroupLayout.PREFERRED_SIZE, 297,
10.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
javax.swing.GroupLayout.PREFERRED_SIZE)
313 .addGap(28, 28, 28))
314 );
315 jPanel5Layout.setVerticalGroup(
316 jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
317 .addGroup(jPanel5Layout.createSequentialGroup()
318 .addContainerGap()
319 .addComponent(txtfieldProductID, javax.swing.GroupLayout.PREFERRED_SIZE, 88,
javax.swing.GroupLayout.PREFERRED_SIZE)
320 .addContainerGap())
321 );
322
323 panelPOS.add(jPanel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(433, 123, 320, 110));
324 panelPOS.add(lblSPAR_LOGO, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 20, 510, 90));
325
326 btnPay.setText("PAY");
327 btnPay.addActionListener(new java.awt.event.ActionListener() {
328 public void actionPerformed(java.awt.event.ActionEvent evt) {
329 btnPayActionPerformed(evt);
330 }
331 });
332
333 btnAdmin.setText("ADMIN");
334 btnAdmin.addActionListener(new java.awt.event.ActionListener() {
335 public void actionPerformed(java.awt.event.ActionEvent evt) {
336 btnAdminActionPerformed(evt);
337 }
338 });
339
340 btnPrint.setText("PRINT");
341 btnPrint.addActionListener(new java.awt.event.ActionListener() {
342 public void actionPerformed(java.awt.event.ActionEvent evt) {
343 btnPrintActionPerformed(evt);
11.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
344 }
345 });
346
347 btnNewOrder.setText("NEW");
348 btnNewOrder.addActionListener(new java.awt.event.ActionListener() {
349 public void actionPerformed(java.awt.event.ActionEvent evt) {
350 btnNewOrderActionPerformed(evt);
351 }
352 });
353
354 javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
355 jPanel6.setLayout(jPanel6Layout);
356 jPanel6Layout.setHorizontalGroup(
357 jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
358 .addGroup(jPanel6Layout.createSequentialGroup()
359 .addGap(10, 10, 10)
360 .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
361 .addComponent(btnAdmin, javax.swing.GroupLayout.PREFERRED_SIZE, 170,
javax.swing.GroupLayout.PREFERRED_SIZE)
362 .addComponent(btnPay, javax.swing.GroupLayout.PREFERRED_SIZE, 170,
javax.swing.GroupLayout.PREFERRED_SIZE)
363 .addComponent(btnPrint, javax.swing.GroupLayout.PREFERRED_SIZE, 170,
javax.swing.GroupLayout.PREFERRED_SIZE))
364 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
365 .addGroup(jPanel6Layout.createSequentialGroup()
366 .addContainerGap()
367 .addComponent(btnNewOrder, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
368 .addContainerGap())
369 );
370 jPanel6Layout.setVerticalGroup(
371 jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
372 .addGroup(jPanel6Layout.createSequentialGroup()
12.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
373 .addGap(110, 110, 110)
374 .addComponent(btnAdmin, javax.swing.GroupLayout.PREFERRED_SIZE, 73,
javax.swing.GroupLayout.PREFERRED_SIZE)
375 .addGap(17, 17, 17)
376 .addComponent(btnPay, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
377 .addGap(17, 17, 17)
378 .addComponent(btnPrint, javax.swing.GroupLayout.PREFERRED_SIZE, 73,
javax.swing.GroupLayout.PREFERRED_SIZE)
379 .addGap(18, 18, 18)
380 .addComponent(btnNewOrder, javax.swing.GroupLayout.PREFERRED_SIZE, 73,
javax.swing.GroupLayout.PREFERRED_SIZE)
381 .addContainerGap())
382 );
383
384 panelPOS.add(jPanel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(760, 130, 190, 480));
385
386 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
387 getContentPane().setLayout(layout);
388 layout.setHorizontalGroup(
389 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
390 .addGroup(layout.createSequentialGroup()
391 .addContainerGap()
392 .addComponent(panelPOS, javax.swing.GroupLayout.DEFAULT_SIZE, 964, Short.MAX_VALUE)
393 .addContainerGap())
394 );
395 layout.setVerticalGroup(
396 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
397 .addGroup(layout.createSequentialGroup()
398 .addContainerGap()
399 .addComponent(panelPOS, javax.swing.GroupLayout.DEFAULT_SIZE, 643, Short.MAX_VALUE)
400 .addContainerGap())
401 );
402
13.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
403 pack();
404 }// </editor-fold>
405
406 private void setTxtAreaProducts(){
407
408 String header = String.format("%-15.10S %-6s %7.4s \n", "PRODUCT", "WEIGHT", "COST");
409
410 txtareaProducts.setText(header + "------------------------------\n\n");
411 }
412
413 private void convertLOGO() {
414
415 ImageIcon logo;
416 Image temp;
417
418 logo = new ImageIcon(getClass().getResource("/images/lg_SPAR.png"));
419 temp = logo.getImage().getScaledInstance(lblSPAR_LOGO.getWidth(), lblSPAR_LOGO.getHeight(),
java.awt.Image.SCALE_DEFAULT);
420 logo = new ImageIcon(temp);
421
422 lblSPAR_LOGO.setIcon(logo);
423 }
424
425 private String formatProduct(ResultSet results) throws SQLException{
426
427 String product = "";
428
429 product = String.format("%-15.15S %-8.8S %5.4s \n",
430 results.getString("brand") + " " + results.getString("productName"),
431 results.getString("weight"),
432 results.getString("cost"));
433
434 return product;
14.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
435 }
436
437 private void updateProducts() {
438
439 try {
440
441 resultset = db.findProduct(txtfieldProductID.getText());
442
443 if(resultset.next())
444 txtareaProducts.append(formatProduct(resultset));
445
446 else{
447
448 txtfieldProductID.setText("INVALID ID");
449 isInvalid = true;
450 }
451
452 double previousCost = Double.valueOf(txtfieldTotalCost.getText());
453
454 double newCost = Double.valueOf(resultset.getString("cost"));
455
456 txtfieldProductID.setText("");
457
458 String reformattedTotal = new DecimalFormat("0.00").format( previousCost + newCost ).replace(',', '.');
459
460 txtfieldTotalCost.setText(reformattedTotal);
461
462 } catch (SQLException ex) {
463
464 System.out.println(ex.toString());
465 }
466 }
467
15.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
468 private void checkProductCode(String num){
469
470 if(isInvalid){
471
472 txtfieldProductID.setText("");
473 isInvalid = false;
474 }
475
476 if (txtfieldProductID.getText().length() < 7) {
477
478
479 txtfieldProductID.setText(txtfieldProductID.getText() + num);
480
481 if (txtfieldProductID.getText().length() == 7) {
482
483 updateProducts();
484 }
485 }
486 else {
487
488 txtfieldProductID.setText(txtfieldProductID.getText());
489 }
490
491 }
492
493 public void clearData(){
494
495 txtfieldProductID.setText("");
496 //setTxtAreaProducts();
497 txtfieldTotalCost.setText("");
498 }
499
500 private void btnSevenActionPerformed(java.awt.event.ActionEvent evt) {
16.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
501
502 checkProductCode("7");
503 }
504
505 private void btnZeroActionPerformed(java.awt.event.ActionEvent evt) {
506
507 checkProductCode("0");
508 }
509
510 private void btnOneActionPerformed(java.awt.event.ActionEvent evt) {
511
512 checkProductCode("1");
513 }
514
515 private void btnTwoActionPerformed(java.awt.event.ActionEvent evt) {
516
517 checkProductCode("2");
518 }
519
520 private void btnThreeActionPerformed(java.awt.event.ActionEvent evt) {
521
522 checkProductCode("3");
523 }
524
525 private void btnFourActionPerformed(java.awt.event.ActionEvent evt) {
526
527 checkProductCode("4");
528 }
529
530 private void btnFiveActionPerformed(java.awt.event.ActionEvent evt) {
531
532 checkProductCode("5");
533 }
17.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
534
535 private void btnSixActionPerformed(java.awt.event.ActionEvent evt) {
536
537 checkProductCode("6");
538 }
539
540 private void btnEightActionPerformed(java.awt.event.ActionEvent evt) {
541
542 checkProductCode("8");
543 }
544
545 private void btnNineActionPerformed(java.awt.event.ActionEvent evt) {
546
547 checkProductCode("9");
548 }
549
550 private void btnDelActionPerformed(java.awt.event.ActionEvent evt) {
551
552 int length = txtfieldProductID.getText().length() - 1;
553
554 if (length >= 0) {
555 txtfieldProductID.setText(txtfieldProductID.getText().substring(0, length));
556 }
557
558 }
559
560 private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {
561 txtfieldProductID.setText("");
562 }
563
564 private void btnPayActionPerformed(java.awt.event.ActionEvent evt) {
565
566 Pay screenPay = new Pay();
18.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
567
568 screenPay.setTotal(Double.valueOf(txtfieldTotalCost.getText()));
569
570 screenPay.setVisible(true);
571 }
572
573 private void btnAdminActionPerformed(java.awt.event.ActionEvent evt) {
574
575 Admin screenAdmin = new Admin();
576
577 screenAdmin.setVisible(true);
578 }
579
580 private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {
581
582 String total, receipt;
583
584 receipt = txtareaProducts.getText() + "\n------------------------------\nTOTAL";
585
586 total = String.format("%25.5s \n", txtfieldTotalCost.getText());
587
588 receipt += total;
589
590 toReceipt.printReceipt(receipt);
591
592 if(!isPrinted)
593 txtareaProducts.append("\n--------------------\nReceipt Printed\n--------------------\n");
594
595 else
596 isPrinted = true;
597
598 }
599
19.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
600 private void btnNewOrderActionPerformed(java.awt.event.ActionEvent evt) {
601
602 setTxtAreaProducts();
603 txtfieldTotalCost.setText("0.00");
604 }
605
606 private void txtfieldProductIDActionPerformed(java.awt.event.ActionEvent evt) {
607 // TODO add your handling code here:
608 }
609
610 /**
611 * @param args the command line arguments
612 */
613 public static void main(String args[]) {
614 /* Set the Nimbus look and feel */
615 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
616 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
617 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
618 */
619 try {
620 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
621 if ("Nimbus".equals(info.getName())) {
622 javax.swing.UIManager.setLookAndFeel(info.getClassName());
623 break;
624 }
625 }
626 } catch (ClassNotFoundException ex) {
627 java.util.logging.Logger.getLogger(POS.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
628 } catch (InstantiationException ex) {
629 java.util.logging.Logger.getLogger(POS.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
630 } catch (IllegalAccessException ex) {
631 java.util.logging.Logger.getLogger(POS.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
632 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
20.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
633 java.util.logging.Logger.getLogger(POS.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
634 }
635 //</editor-fold>
636
637 /* Create and display the form */
638 java.awt.EventQueue.invokeLater(new Runnable() {
639 public void run() {
640 new POS().setVisible(true);
641 }
642 });
643 }
644
645 // Variables declaration - do not modify
646 private javax.swing.JButton btnAdmin;
647 private javax.swing.JButton btnClear;
648 private javax.swing.JButton btnDel;
649 private javax.swing.JButton btnEight;
650 private javax.swing.JButton btnFive;
651 private javax.swing.JButton btnFour;
652 private javax.swing.JButton btnNewOrder;
653 private javax.swing.JButton btnNine;
654 private javax.swing.JButton btnOne;
655 private javax.swing.JButton btnPay;
656 private javax.swing.JButton btnPrint;
657 private javax.swing.JButton btnSeven;
658 private javax.swing.JButton btnSix;
659 private javax.swing.JButton btnThree;
660 private javax.swing.JButton btnTwo;
661 private javax.swing.JButton btnZero;
662 private javax.swing.JPanel jPanel2;
663 private javax.swing.JPanel jPanel3;
664 private javax.swing.JPanel jPanel4;
665 private javax.swing.JPanel jPanel5;
21.1 of 22 2022.12.11 13:43:22
C:/Users/User/Desktop/OneDrive - Curro Holdings/1. OneDrive/Documents/NetBeansProjects/G12_SkyPAT/src/screens/POS.java
666 private javax.swing.JPanel jPanel6;
667 private javax.swing.JScrollPane jScrollPane1;
668 private javax.swing.JLabel lblSPAR_LOGO;
669 private javax.swing.JPanel panelPOS;
670 private javax.swing.JTextArea txtareaProducts;
671 private javax.swing.JTextField txtfieldProductID;
672 private javax.swing.JTextField txtfieldTotalCost;
673 // End of variables declaration
674 }

22.1 of 22 2022.12.11 13:43:22

You might also like