Java tutorial
/* * 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 coffeshop; import java.awt.CardLayout; import java.math.BigDecimal; import java.math.RoundingMode; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Calendar; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.ImageIcon; import javax.swing.JOptionPane; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.InputStream; import java.io.File; import net.glxn.qrgen.QRCode; import net.glxn.qrgen.image.ImageType; import java.io.ByteArrayOutputStream; import java.io.ByteArrayInputStream; import org.json.JSONException; import org.json.JSONObject; import org.json.*; import org.apache.commons.io.*; import java.net.URL; import java.net.MalformedURLException; import java.io.IOException; import java.util.Timer; import java.util.TimerTask; /** * * @author Ghin */ public class PaymentPage extends javax.swing.JFrame { /** * Creates new form Payment */ boolean timeExpired; boolean timeStop; public PaymentPage(MainPage mmain, int currentOrder, String mtransType, ResultSet memp, List<Button> mproducts, String mpromoCode, BigDecimal msubtotal, BigDecimal mpromo, BigDecimal mtax, BigDecimal mtotal) { initComponents(); main = mmain; transID = currentOrder; rsMan = memp; try { emp_id = rsMan.getInt(1); } catch (SQLException ex) { Logger.getLogger(PaymentPage.class.getName()).log(Level.SEVERE, null, ex); } products = new ArrayList<>(); for (Button i : mproducts) { products.add(i); } lblQRC.setIcon(defaultQR); transType = mtransType; promoCode = mpromoCode; subtotal = msubtotal; promo = mpromo; tax = mtax; total = mtotal; lblPromo.setText(String.valueOf(promo)); lblSubtotal.setText(String.valueOf(subtotal)); lblTax.setText(String.valueOf(tax)); lblTotal.setText(String.valueOf(total)); paid = BigDecimal.ZERO; showPanel("card2"); paymentMethod = "CA"; payments = new ArrayList<>(); calculateDue(); timeExpired = false; timeStop = false; } /** * 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() { java.awt.GridBagConstraints gridBagConstraints; buttonGroup1 = new javax.swing.ButtonGroup(); jPanel5 = new javax.swing.JPanel(); jLabel6 = new javax.swing.JLabel(); lblSubtotal = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); lblPromo = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); lblTax = new javax.swing.JLabel(); jLabel10 = new javax.swing.JLabel(); lblTotal = new javax.swing.JLabel(); jpPaymentInput = new javax.swing.JPanel(); jbBitcoin = new javax.swing.JPanel(); lblQRC = new javax.swing.JLabel(); lblBTCDue = new javax.swing.JLabel(); btnScanBTC = new javax.swing.JButton(); btnClearBTC = new javax.swing.JButton(); lblUSDtoBTC = new javax.swing.JLabel(); lblTimer = new javax.swing.JLabel(); jpCreditDebit = new javax.swing.JPanel(); jradCredit = new javax.swing.JRadioButton(); jradDebit = new javax.swing.JRadioButton(); jlblCardNum = new javax.swing.JLabel(); jtfCardNum = new javax.swing.JTextField(); jLabel14 = new javax.swing.JLabel(); jLabel16 = new javax.swing.JLabel(); jTextField2 = new javax.swing.JTextField(); jComboBox1 = new javax.swing.JComboBox<>(); jComboBox2 = new javax.swing.JComboBox<>(); btnSwipe = new javax.swing.JButton(); jSeparator1 = new javax.swing.JSeparator(); btnClear = new javax.swing.JButton(); jpGift = new javax.swing.JPanel(); jlblGiftCardNum = new javax.swing.JLabel(); jtfGiftCardNum = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jpCash = new javax.swing.JPanel(); jbtnNumAmt20 = new javax.swing.JButton(); jbtnNumAmt10 = new javax.swing.JButton(); jbtnNum7 = new javax.swing.JButton(); jbtnNum8 = new javax.swing.JButton(); jbtnNum4 = new javax.swing.JButton(); jbtnNum5 = new javax.swing.JButton(); jbtnNum1 = new javax.swing.JButton(); jbtnNumAmt5 = new javax.swing.JButton(); jbtnNum2 = new javax.swing.JButton(); jbtnNum0 = new javax.swing.JButton(); jbtnNumAmtExact = new javax.swing.JButton(); jbtnNumDot = new javax.swing.JButton(); jbtnNum9 = new javax.swing.JButton(); jbtnNum6 = new javax.swing.JButton(); jbtnNum3 = new javax.swing.JButton(); jbtnNum00 = new javax.swing.JButton(); jbtnEnter = new javax.swing.JButton(); jbtnClear = new javax.swing.JButton(); jtfNumPad = new javax.swing.JTextField(); jpMethod = new javax.swing.JPanel(); jbtnBitcoin = new javax.swing.JButton(); jbtnCash = new javax.swing.JButton(); jbtnGiftCard = new javax.swing.JButton(); jbtnCreditCard = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); txtPayAmt = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); cboSplit = new javax.swing.JComboBox<>(); btnPay = new javax.swing.JButton(); btnCancel = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); jLabel3 = new javax.swing.JLabel(); lblPaid = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); lblDue = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Payment - Krankies"); setResizable(false); jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jPanel5.setLayout(new java.awt.GridLayout(4, 2, 5, 5)); jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); jLabel6.setText("Subtotal:"); jPanel5.add(jLabel6); lblSubtotal.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N lblSubtotal.setText("0.00"); jPanel5.add(lblSubtotal); jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); jLabel7.setText("Discount:"); jPanel5.add(jLabel7); lblPromo.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N lblPromo.setText("0.00"); jPanel5.add(lblPromo); jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); jLabel8.setText("Tax:"); jPanel5.add(jLabel8); lblTax.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N lblTax.setText("0.00"); jPanel5.add(lblTax); jLabel10.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); jLabel10.setText("Total:"); jPanel5.add(jLabel10); lblTotal.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N lblTotal.setText("0.00"); jPanel5.add(lblTotal); jpPaymentInput.setLayout(new java.awt.CardLayout(5, 5)); jbBitcoin.setVisible(false); jbBitcoin.setBorder(javax.swing.BorderFactory.createEtchedBorder()); lblQRC.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); lblQRC.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ImageRes/defaultQR.png"))); // NOI18N lblBTCDue.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N btnScanBTC.setText("Scan Code"); btnScanBTC.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnScanBTCActionPerformed(evt); } }); btnClearBTC.setText("Clear"); btnClearBTC.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnClearBTCActionPerformed(evt); } }); lblUSDtoBTC.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N lblTimer.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N lblTimer.setText(" "); javax.swing.GroupLayout jbBitcoinLayout = new javax.swing.GroupLayout(jbBitcoin); jbBitcoin.setLayout(jbBitcoinLayout); jbBitcoinLayout .setHorizontalGroup(jbBitcoinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jbBitcoinLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnScanBTC) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnClearBTC, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(198, 198, 198)) .addGroup(jbBitcoinLayout.createSequentialGroup().addGap(39, 39, 39) .addComponent(lblBTCDue, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(jbBitcoinLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(lblUSDtoBTC, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(lblQRC, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(44, 44, 44) .addComponent(lblTimer, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(63, Short.MAX_VALUE))); jbBitcoinLayout.setVerticalGroup(jbBitcoinLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jbBitcoinLayout.createSequentialGroup().addGroup(jbBitcoinLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jbBitcoinLayout.createSequentialGroup().addGap(72, 72, 72).addComponent(lblBTCDue, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jbBitcoinLayout.createSequentialGroup().addContainerGap().addComponent(lblQRC)) .addGroup(jbBitcoinLayout.createSequentialGroup().addGap(69, 69, 69).addComponent(lblTimer, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(lblUSDtoBTC, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jbBitcoinLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnScanBTC).addComponent(btnClearBTC)) .addGap(21, 21, 21))); jpPaymentInput.add(jbBitcoin, "card3"); jpCreditDebit.setVisible(false); jpCreditDebit.setBorder(javax.swing.BorderFactory.createEtchedBorder()); buttonGroup1.add(jradCredit); jradCredit.setSelected(true); jradCredit.setText("Credit"); jradCredit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jradCreditActionPerformed(evt); } }); buttonGroup1.add(jradDebit); jradDebit.setText("Debit"); jradDebit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jradDebitActionPerformed(evt); } }); jlblCardNum.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jlblCardNum.setText("Card Number"); jtfCardNum.setMinimumSize(new java.awt.Dimension(6, 24)); jLabel14.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jLabel14.setText("Expiration Date"); jLabel16.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jLabel16.setText("CCV"); jTextField2.setPreferredSize(new java.awt.Dimension(6, 24)); jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>( new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" })); jComboBox2.setModel(new javax.swing.DefaultComboBoxModel<>( new String[] { "17", "18", "19", "20", "21", "22", "23", "24", "25" })); btnSwipe.setText("Swipe or Insert card"); btnSwipe.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSwipeActionPerformed(evt); } }); btnClear.setText("Clear"); btnClear.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnClearActionPerformed(evt); } }); javax.swing.GroupLayout jpCreditDebitLayout = new javax.swing.GroupLayout(jpCreditDebit); jpCreditDebit.setLayout(jpCreditDebitLayout); jpCreditDebitLayout.setHorizontalGroup(jpCreditDebitLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpCreditDebitLayout.createSequentialGroup() .addContainerGap(132, Short.MAX_VALUE) .addGroup(jpCreditDebitLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( jpCreditDebitLayout.createSequentialGroup().addGroup(jpCreditDebitLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jradCredit).addComponent(jlblCardNum) .addComponent( jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(27, 27, 27) .addGroup(jpCreditDebitLayout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jtfCardNum, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jradDebit) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jpCreditDebitLayout.createSequentialGroup() .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 321, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jpCreditDebitLayout.createSequentialGroup().addGap(29, 29, 29) .addComponent(btnSwipe).addGap(32, 32, 32).addComponent(btnClear))) .addGap(67, 67, 67))); jpCreditDebitLayout .setVerticalGroup(jpCreditDebitLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpCreditDebitLayout.createSequentialGroup().addContainerGap(16, Short.MAX_VALUE) .addGroup(jpCreditDebitLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jradCredit).addComponent(jradDebit)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jpCreditDebitLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jlblCardNum).addComponent(jtfCardNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jpCreditDebitLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel14) .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jpCreditDebitLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel16).addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jpCreditDebitLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnSwipe).addComponent(btnClear)) .addContainerGap())); jpPaymentInput.add(jpCreditDebit, "card4"); jpGift.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jpGift.setVisible(false); jlblGiftCardNum.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jlblGiftCardNum.setText("Gift Card Number"); jButton1.setText("Check Balance"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout jpGiftLayout = new javax.swing.GroupLayout(jpGift); jpGift.setLayout(jpGiftLayout); jpGiftLayout.setHorizontalGroup(jpGiftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jpGiftLayout.createSequentialGroup().addGap(86, 86, 86).addComponent(jlblGiftCardNum) .addGap(18, 18, 18) .addGroup(jpGiftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jtfGiftCardNum, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(132, Short.MAX_VALUE))); jpGiftLayout.setVerticalGroup(jpGiftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpGiftLayout.createSequentialGroup() .addContainerGap(85, Short.MAX_VALUE) .addGroup(jpGiftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jlblGiftCardNum).addComponent(jtfGiftCardNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18).addComponent(jButton1).addGap(47, 47, 47))); jpPaymentInput.add(jpGift, "card5"); jpCash.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jpCash.setLayout(new java.awt.GridBagLayout()); jbtnNumAmt20.setText("20.00"); jbtnNumAmt20.setPreferredSize(new java.awt.Dimension(80, 23)); jbtnNumAmt20.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnNumAmt20ActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); jpCash.add(jbtnNumAmt20, gridBagConstraints); jbtnNumAmt10.setText("10.00"); jbtnNumAmt10.setPreferredSize(new java.awt.Dimension(80, 23)); jbtnNumAmt10.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnNumAmt10ActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 2; gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); jpCash.add(jbtnNumAmt10, gridBagConstraints); jbtnNum7.setText("7"); jbtnNum7.setMaximumSize(null); jbtnNum7.setPreferredSize(new java.awt.Dimension(59, 23)); jbtnNum7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnNum7ActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); jpCash.add(jbtnNum7, gridBagConstraints); jbtnNum8.setText("8"); jbtnNum8.setMaximumSize(null); jbtnNum8.setPreferredSize(new java.awt.Dimension(59, 23)); jbtnNum8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnNum8ActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridy = 1; gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); jpCash.add(jbtnNum8, gridBagConstraints); jbtnNum4.setText("4"); jbtnNum4.setMaximumSize(null); jbtnNum4.setPreferredSize(new java.awt.Dimension(59, 23)); jbtnNum4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnNum4ActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); jpCash.add(jbtnNum4, gridBagConstraints); jbtnNum5.setText("5"); jbtnNum5.setMaximumSize(null); jbtnNum5.setPreferredSize(new java.awt.Dimension(59, 23)); jbtnNum5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnNum5ActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); jpCash.add(jbtnNum5, gridBagConstraints); jbtnNum1.setText("1"); jbtnNum1.setMaximumSize(null); jbtnNum1.setPreferredSize(new java.awt.Dimension(59, 23)); jbtnNum1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnNum1ActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); jpCash.add(jbtnNum1, gridBagConstraints); jbtnNumAmt5.setText("5.00"); jbtnNumAmt5.setMinimumSize(new java.awt.Dimension(59, 23)); jbtnNumAmt5.setPreferredSize(new java.awt.Dimension(80, 23)); jbtnNumAmt5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnNumAmt5ActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 3; gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); jpCash.add(jbtnNumAmt5, gridBagConstraints); jbtnNum2.setText("2"); jbtnNum2.setMaximumSize(null); jbtnNum2.setPreferredSize(new java.awt.Dimension(59, 23)); jbtnNum2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnNum2ActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); jpCash.add(jbtnNum2, gridBagConstraints); jbtnNum0.setText("0"); jbtnNum0.setMaximumSize(null); jbtnNum0.setPreferredSize(new java.awt.Dimension(59, 23)); jbtnNum0.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnNum0ActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); jpCash.add(jbtnNum0, gridBagConstraints); jbtnNumAmtExact.setText("Exact"); jbtnNumAmtExact.setMaximumSize(null); jbtnNumAmtExact.setPreferredSize(new java.awt.Dimension(80, 23)); jbtnNumAmtExact.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnNumAmtExactActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 4; gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); jpCash.add(jbtnNumAmtExact, gridBagConstraints); jbtnNumDot.setText("."); jbtnNumDot.setMaximumSize(null); jbtnNumDot.setPreferredSize(new java.awt.Dimension(59, 23)); jbtnNumDot.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnNumDotActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 4; gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); jpCash.add(jbtnNumDot, gridBagConstraints); jbtnNum9.setText("9"); jbtnNum9.setMaximumSize(null); jbtnNum9.setPreferredSize(new java.awt.Dimension(59, 23)); jbtnNum9.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnNum9ActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 1; gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); jpCash.add(jbtnNum9, gridBagConstraints); jbtnNum6.setText("6"); jbtnNum6.setMaximumSize(null); jbtnNum6.setPreferredSize(new java.awt.Dimension(59, 23)); jbtnNum6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnNum6ActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 2; gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); jpCash.add(jbtnNum6, gridBagConstraints); jbtnNum3.setText("3"); jbtnNum3.setMaximumSize(null); jbtnNum3.setPreferredSize(new java.awt.Dimension(59, 23)); jbtnNum3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnNum3ActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 3; gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); jpCash.add(jbtnNum3, gridBagConstraints); jbtnNum00.setText("00"); jbtnNum00.setMaximumSize(null); jbtnNum00.setPreferredSize(new java.awt.Dimension(59, 23)); jbtnNum00.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnNum00ActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 4; gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); jpCash.add(jbtnNum00, gridBagConstraints); jbtnEnter.setText("Delete"); jbtnEnter.setPreferredSize(new java.awt.Dimension(149, 30)); jbtnEnter.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnEnterActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 5; gridBagConstraints.gridwidth = 2; gridBagConstraints.gridheight = 2; jpCash.add(jbtnEnter, gridBagConstraints); jbtnClear.setText("Clear"); jbtnClear.setPreferredSize(new java.awt.Dimension(140, 30)); jbtnClear.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnClearActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 5; gridBagConstraints.gridwidth = 2; gridBagConstraints.gridheight = 2; jpCash.add(jbtnClear, gridBagConstraints); jtfNumPad.setEditable(false); jtfNumPad.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N jtfNumPad.setHorizontalAlignment(javax.swing.JTextField.RIGHT); jtfNumPad.setText("0.00"); jtfNumPad.setMargin(new java.awt.Insets(2, 2, 2, 10)); jtfNumPad.setPreferredSize(new java.awt.Dimension(282, 34)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 4; gridBagConstraints.insets = new java.awt.Insets(4, 1, 4, 1); jpCash.add(jtfNumPad, gridBagConstraints); jpPaymentInput.add(jpCash, "card2"); jpMethod.setLayout(new java.awt.GridLayout(2, 2)); jbtnBitcoin.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jbtnBitcoin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ImageRes/bitcoin-coin.png"))); // NOI18N jbtnBitcoin.setText(" Bitcoin"); jbtnBitcoin.setMaximumSize(new java.awt.Dimension(129, 48)); jbtnBitcoin.setMinimumSize(new java.awt.Dimension(129, 48)); jbtnBitcoin.setPreferredSize(new java.awt.Dimension(129, 48)); jbtnBitcoin.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnBitcoinActionPerformed(evt); } }); jpMethod.add(jbtnBitcoin); jbtnCash.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jbtnCash.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ImageRes/money.png"))); // NOI18N jbtnCash.setText(" Cash"); jbtnCash.setMaximumSize(new java.awt.Dimension(129, 48)); jbtnCash.setMinimumSize(new java.awt.Dimension(129, 48)); jbtnCash.setPreferredSize(new java.awt.Dimension(129, 48)); jbtnCash.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnCashActionPerformed(evt); } }); jpMethod.add(jbtnCash); jbtnGiftCard.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jbtnGiftCard .setIcon(new javax.swing.ImageIcon(getClass().getResource("/ImageRes/christmas-gift-card.png"))); // NOI18N jbtnGiftCard.setText(" Gift Card"); jbtnGiftCard.setToolTipText(""); jbtnGiftCard.setMaximumSize(new java.awt.Dimension(129, 48)); jbtnGiftCard.setMinimumSize(new java.awt.Dimension(129, 48)); jbtnGiftCard.setPreferredSize(new java.awt.Dimension(129, 48)); jbtnGiftCard.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnGiftCardActionPerformed(evt); } }); jpMethod.add(jbtnGiftCard); jbtnCreditCard.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jbtnCreditCard.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ImageRes/credit-card.png"))); // NOI18N jbtnCreditCard.setText(" Credit Card"); jbtnCreditCard.setMaximumSize(new java.awt.Dimension(187, 48)); jbtnCreditCard.setMinimumSize(new java.awt.Dimension(187, 48)); jbtnCreditCard.setPreferredSize(new java.awt.Dimension(129, 48)); jbtnCreditCard.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnCreditCardActionPerformed(evt); } }); jpMethod.add(jbtnCreditCard); jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jLabel1.setText("Payment Amount"); txtPayAmt.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N txtPayAmt.setText("0.00"); jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jLabel2.setText("Split"); cboSplit.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N cboSplit.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1", "2", "3", "4" })); cboSplit.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { cboSplitItemStateChanged(evt); } }); btnPay.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N btnPay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ImageRes/ic_payment_black_48dp_1x.png"))); // NOI18N btnPay.setText("Pay"); btnPay.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnPayActionPerformed(evt); } }); btnCancel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N btnCancel.setIcon( new javax.swing.ImageIcon(getClass().getResource("/ImageRes/ic_cancel_black_48dp_1x.png"))); // NOI18N btnCancel.setText("Cancel"); btnCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCancelActionPerformed(evt); } }); jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jPanel2.setLayout(new java.awt.GridLayout(2, 2, 5, 5)); jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); jLabel3.setText("Paid:"); jPanel2.add(jLabel3); lblPaid.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N lblPaid.setText("0.00"); jPanel2.add(lblPaid); jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); jLabel4.setText("Amount Due:"); jPanel2.add(jLabel4); lblDue.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N lblDue.setText("0.00"); jPanel2.add(lblDue); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jpPaymentInput, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jpMethod, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(35, 35, 35) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel2).addComponent(jLabel1)) .addGap(18, 18, 18) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txtPayAmt, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(cboSplit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addComponent(btnCancel) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(btnPay))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(19, 19, 19) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jpMethod, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent( jpPaymentInput, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1).addComponent(txtPayAmt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(11, 11, 11) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2).addComponent(cboSplit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnCancel).addComponent(btnPay)) .addGap(34, 34, 34))))); pack(); setLocationRelativeTo(null); }// </editor-fold>//GEN-END:initComponents private void jbtnNumAmt20ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNumAmt20ActionPerformed cashPaymentOutput = "20.00"; jtfNumPad.setText(cashPaymentOutput); }//GEN-LAST:event_jbtnNumAmt20ActionPerformed private void jbtnNumAmt10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNumAmt10ActionPerformed cashPaymentOutput = "10.00"; jtfNumPad.setText(cashPaymentOutput); }//GEN-LAST:event_jbtnNumAmt10ActionPerformed private void jbtnNum7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNum7ActionPerformed cashPaymentOutput += "7"; jtfNumPad.setText(cashPaymentOutput); }//GEN-LAST:event_jbtnNum7ActionPerformed private void jbtnNum8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNum8ActionPerformed cashPaymentOutput += "8"; jtfNumPad.setText(cashPaymentOutput); }//GEN-LAST:event_jbtnNum8ActionPerformed private void jbtnNum4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNum4ActionPerformed cashPaymentOutput += "4"; jtfNumPad.setText(cashPaymentOutput); }//GEN-LAST:event_jbtnNum4ActionPerformed private void jbtnNum5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNum5ActionPerformed cashPaymentOutput += "5"; jtfNumPad.setText(cashPaymentOutput); }//GEN-LAST:event_jbtnNum5ActionPerformed private void jbtnNum1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNum1ActionPerformed cashPaymentOutput += "1"; jtfNumPad.setText(cashPaymentOutput); }//GEN-LAST:event_jbtnNum1ActionPerformed private void jbtnNumAmt5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNumAmt5ActionPerformed cashPaymentOutput = "5.00"; jtfNumPad.setText(cashPaymentOutput); }//GEN-LAST:event_jbtnNumAmt5ActionPerformed private void jbtnNum2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNum2ActionPerformed cashPaymentOutput += "2"; jtfNumPad.setText(cashPaymentOutput); }//GEN-LAST:event_jbtnNum2ActionPerformed private void jbtnNum0ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNum0ActionPerformed cashPaymentOutput += "0"; jtfNumPad.setText(cashPaymentOutput); }//GEN-LAST:event_jbtnNum0ActionPerformed private void jbtnNumAmtExactActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNumAmtExactActionPerformed cashPaymentOutput = txtPayAmt.getText(); jtfNumPad.setText(cashPaymentOutput); }//GEN-LAST:event_jbtnNumAmtExactActionPerformed private void jbtnNumDotActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNumDotActionPerformed if (!cashPaymentOutput.contains(".")) { cashPaymentOutput += "."; jtfNumPad.setText(cashPaymentOutput); } }//GEN-LAST:event_jbtnNumDotActionPerformed private void jbtnNum9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNum9ActionPerformed cashPaymentOutput += "9"; jtfNumPad.setText(cashPaymentOutput); }//GEN-LAST:event_jbtnNum9ActionPerformed private void jbtnNum6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNum6ActionPerformed cashPaymentOutput += "6"; jtfNumPad.setText(cashPaymentOutput); }//GEN-LAST:event_jbtnNum6ActionPerformed private void jbtnNum3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNum3ActionPerformed cashPaymentOutput += "3"; jtfNumPad.setText(cashPaymentOutput); }//GEN-LAST:event_jbtnNum3ActionPerformed private void jbtnNum00ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNum00ActionPerformed cashPaymentOutput += "00"; jtfNumPad.setText(cashPaymentOutput); }//GEN-LAST:event_jbtnNum00ActionPerformed private void jbtnEnterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnEnterActionPerformed String paymentInput = jtfNumPad.getText(); if (paymentInput.length() != 0) { paymentInput = paymentInput.substring(0, paymentInput.length() - 1); jtfNumPad.setText(paymentInput); } }//GEN-LAST:event_jbtnEnterActionPerformed private void jbtnClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnClearActionPerformed cashPaymentOutput = ""; jtfNumPad.setText("0.00"); }//GEN-LAST:event_jbtnClearActionPerformed private void jbtnCreditCardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnCreditCardActionPerformed paymentMethod = "CC"; resetAll(); jradCredit.isSelected(); showPanel("card4"); }//GEN-LAST:event_jbtnCreditCardActionPerformed private void jbtnGiftCardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnGiftCardActionPerformed paymentMethod = "GC"; resetAll(); showPanel("card5"); }//GEN-LAST:event_jbtnGiftCardActionPerformed private void jbtnBitcoinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnBitcoinActionPerformed paymentMethod = "BC"; resetAll(); showPanel("card3"); }//GEN-LAST:event_jbtnBitcoinActionPerformed private void generateQR(String btcPay) throws Exception { BigDecimal dollar = new BigDecimal(btcPay); BigDecimal btcPriceIndex = btcPriceIndex(); BigDecimal btc = dollar.divide(btcPriceIndex, 5, BigDecimal.ROUND_HALF_UP); byte[] imageInByte; BufferedImage originalImage = ImageIO.read(new File("src/ImageRes/QR.jpg")); String details = "bitcoin:12nAq7bJSkKFxJYaHjhjfPAaZ6sXgLqBJ7?amount=" + btc; QRCode.from(details).withSize(125, 125).file(); QRCode.from(details).withSize(125, 125).stream(); ByteArrayOutputStream out = QRCode.from(details).to(ImageType.JPG).stream(); ImageIO.write(originalImage, "jpg", out); out.flush(); imageInByte = out.toByteArray(); out.close(); InputStream in = new ByteArrayInputStream(imageInByte); BufferedImage bImageFromConvert = ImageIO.read(in); ImageIO.write(bImageFromConvert, "jpg", new File("src/ImageRes/QR.jpg")); } public BigDecimal btcPriceIndex() { try { JSONObject jo = (JSONObject) new JSONTokener(IOUtils.toString(new URL("http://api.coindesk.com/v1/bpi/currentprice/USD.json").openStream())).nextValue(); String priceIndex = jo.getJSONObject("bpi").getJSONObject("USD").getString("rate"); priceIndex = priceIndex.replace(",", ""); BigDecimal btcPriceInUSD = new BigDecimal(priceIndex); return btcPriceInUSD; } catch (MalformedURLException e) { JOptionPane.showMessageDialog(null, "Error connecting to price index url"); e.printStackTrace(); } catch (IOException e) { JOptionPane.showMessageDialog(null, "Error reading price index"); e.printStackTrace(); } catch (JSONException e) { JOptionPane.showMessageDialog(null, "Error getting price index"); e.printStackTrace(); } return null; } private void btcTimer() { Timer timer = new Timer(); //new timer timeExpired = false; TimerTask task = new TimerTask() { int counter = 10; public void run() { int minutes = 0; int seconds = 0; minutes = counter / 60; seconds = counter % 60; if (timeStop) { timer.cancel(); timer.purge(); } else { String timeString = String.format("Time Left: %02d:%02d", minutes, seconds); lblTimer.setText(timeString); counter--; if (counter == -1) { timer.cancel(); timer.purge(); lblTimer.setText("Time Expired"); timeExpired = true; lblQRC.setIcon(defaultQR); } } } }; timer.scheduleAtFixedRate(task, 1000, 1000); } private void jbtnCashActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnCashActionPerformed paymentMethod = "CA"; resetAll(); showPanel("card2"); }//GEN-LAST:event_jbtnCashActionPerformed private void cboSplitItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboSplitItemStateChanged int split = cboSplit.getSelectedIndex() + 1; txtPayAmt.setText((due.divide(new BigDecimal(split), 2, RoundingMode.HALF_UP)).toString()); }//GEN-LAST:event_cboSplitItemStateChanged private void btnClearBTCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClearBTCActionPerformed clearBTC(); }//GEN-LAST:event_btnClearBTCActionPerformed public void clearBTC() { btnScanBTC.setEnabled(true); lblQRC.setIcon(defaultQR); lblUSDtoBTC.setText(""); lblBTCDue.setText(""); lblTimer.setText(""); timeStop = true; } private void btnScanBTCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnScanBTCActionPerformed timeStop = false; btnScanBTC.setEnabled(false); btcTimer(); String btcPay = txtPayAmt.getText(); BigDecimal USD = new BigDecimal(btcPay); BigDecimal USDtoBTC = btcPriceIndex(); BigDecimal BTCDue = USD.divide(USDtoBTC, 5, BigDecimal.ROUND_HALF_UP); USDtoBTC = USDtoBTC.setScale(2, BigDecimal.ROUND_HALF_UP); lblUSDtoBTC.setText("USD/BTC = " + USDtoBTC); lblBTCDue.setText("BTC Due: " + BTCDue); try { generateQR(btcPay); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Error generating QR Code"); ex.printStackTrace(); } try { BufferedImage image = ImageIO.read(new File("src/ImageRes/QR.jpg")); ImageIcon icon = new ImageIcon(image); icon.getImage().flush(); lblQRC.setIcon(icon); } catch (IOException ex) { System.out.println(ex.getMessage()); } if (lblQRC.getIcon() == null) { lblQRC.setIcon(defaultQR); JOptionPane.showMessageDialog(null, "Wrong QR Code. Please try again.", "Wrong QR Code", JOptionPane.PLAIN_MESSAGE); } }//GEN-LAST:event_btnScanBTCActionPerformed private Boolean validatePayment() { switch (paymentMethod) { case "CA": if (new BigDecimal(jtfNumPad.getText()).compareTo(new BigDecimal(txtPayAmt.getText())) >= 0) { return true; } break; case "CC": case "DC": if (isValidated) { return true; } else if (jtfCardNum.getText().matches(cardRegExp) && !jTextField2.getText().equals("")) { Calendar cal = Calendar.getInstance(); if ((2000 + Integer.parseInt(jComboBox2.getSelectedItem().toString())) > cal.get(Calendar.YEAR)) { return true; } else if ((2000 + Integer.parseInt(jComboBox2.getSelectedItem().toString())) < cal .get(Calendar.YEAR)) { return false; } else if (Integer .parseInt(jComboBox1.getSelectedItem().toString()) >= (cal.get(Calendar.MONTH) + 1)) { return true; } else { return false; } } break; case "GC": String balance = jtfGiftCardNum.getText(); if (balance.matches(giftRegExp)) { balance = balance.substring(0, 1) + balance.substring(balance.length() - 1); if (new BigDecimal(balance).compareTo(new BigDecimal(txtPayAmt.getText())) >= 0) { return true; } } break; case "BC": if (lblQRC.getIcon() != defaultQR) { return true; } break; } return false; } private void btnPayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPayActionPerformed if (validatePayment()) { BigDecimal payAmt = new BigDecimal(txtPayAmt.getText()); if (due.compareTo(payAmt) >= 0) { due = due.subtract(payAmt); paid = paid.add(payAmt); payments.add(new Payment(paymentMethod, transID, payAmt)); if (cboSplit.getSelectedIndex() > 0) { cboSplit.setSelectedIndex(cboSplit.getSelectedIndex() - 1); } calculateDue(); resetAll(); JOptionPane.showConfirmDialog(null, "Do you want to print receipt?", "Payment Completed.", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); } else { JOptionPane.showMessageDialog(null, "Payment Amount is wrong. Please check again.", "Wrong Payment Amount", JOptionPane.PLAIN_MESSAGE); } if (due.compareTo(BigDecimal.ZERO) == 0 && paid.compareTo(total) == 0) { JOptionPane.showMessageDialog(null, "Payment Completed.", "Payment Completed", JOptionPane.PLAIN_MESSAGE); try { accessor = new DBAccessor(); accessor.connectDB(); if (accessor.insertPayment(emp_id, transType, transID, tax, total, promoCode, products, payments)) { JOptionPane.showMessageDialog(null, "Records have been saved", "Records saved", JOptionPane.PLAIN_MESSAGE); } rsMan.beforeFirst(); } catch (SQLException ex) { Logger.getLogger(PaymentPage.class.getName()).log(Level.SEVERE, null, ex); } main.dispose(); main = new MainPage(rsMan); main.setVisible(true); this.dispose(); } } else { JOptionPane.showMessageDialog(null, "Invalid payment input. Please check again.", "Wrong Payment Amount", JOptionPane.PLAIN_MESSAGE); } }//GEN-LAST:event_btnPayActionPerformed private void jradCreditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jradCreditActionPerformed paymentMethod = "CC"; }//GEN-LAST:event_jradCreditActionPerformed private void jradDebitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jradDebitActionPerformed paymentMethod = "DC"; }//GEN-LAST:event_jradDebitActionPerformed private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed main.setVisible(true); this.dispose(); }//GEN-LAST:event_btnCancelActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed if (jtfGiftCardNum.getText().matches(giftRegExp)) { String balance = jtfGiftCardNum.getText(); balance = balance.substring(0, 1) + balance.substring(balance.length() - 1); JOptionPane.showMessageDialog(null, "Balance: $" + balance, "Balance", JOptionPane.PLAIN_MESSAGE); } else { JOptionPane.showMessageDialog(null, "Invalid Gift Card Number", "Invalid Card", JOptionPane.PLAIN_MESSAGE); } }//GEN-LAST:event_jButton1ActionPerformed private void btnSwipeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSwipeActionPerformed isValidated = true; jtfCardNum.setEnabled(false); jComboBox1.setEnabled(false); jComboBox2.setEnabled(false); jTextField2.setEnabled(false); }//GEN-LAST:event_btnSwipeActionPerformed private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClearActionPerformed isValidated = false; jtfCardNum.setEnabled(true); jComboBox1.setEnabled(true); jComboBox2.setEnabled(true); jTextField2.setEnabled(true); }//GEN-LAST:event_btnClearActionPerformed /** * @param args the command line arguments */ public void resetAll() { //reset CC DC isValidated = false; jtfCardNum.setEnabled(true); jComboBox1.setEnabled(true); jComboBox2.setEnabled(true); jTextField2.setEnabled(true); //reset BC clearBTC(); //reset CA cashPaymentOutput = ""; jtfNumPad.setText("0.00"); //reset GC jtfGiftCardNum.setText(""); } private void calculateDue() { due = total.subtract(paid); lblDue.setText(String.valueOf(due)); lblPaid.setText(String.valueOf(paid)); int split = cboSplit.getSelectedIndex() + 1; txtPayAmt.setText(due.divide(new BigDecimal(split), 2, RoundingMode.HALF_UP).toString()); } private void showPanel(String pnName) { CardLayout layout = (CardLayout) jpPaymentInput.getLayout(); layout.show(jpPaymentInput, pnName); } private Boolean isValidated = false; private DBAccessor accessor; private List<Payment> payments; private int transID = -1; private String giftRegExp = "[1-9][kK]\\w[rR]\\w[aA]\\w[nN]\\w[kK]\\w[iI]\\w[eE]\\w[sS][0-9]"; private String cardRegExp = "^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11})$"; private ResultSet rsMan; private String transType; private ImageIcon defaultQR = new ImageIcon("src/ImageRes/defaultQR.png"); private String cashPaymentOutput = ""; private List<Button> products; private String promoCode; private BigDecimal subtotal; private BigDecimal promo; private BigDecimal tax; private BigDecimal total; private BigDecimal paid; private BigDecimal due; private int emp_id; private String paymentMethod; private MainPage main; // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnCancel; private javax.swing.JButton btnClear; private javax.swing.JButton btnClearBTC; private javax.swing.JButton btnPay; private javax.swing.JButton btnScanBTC; private javax.swing.JButton btnSwipe; private javax.swing.ButtonGroup buttonGroup1; private javax.swing.JComboBox<String> cboSplit; private javax.swing.JButton jButton1; private javax.swing.JComboBox<String> jComboBox1; private javax.swing.JComboBox<String> jComboBox2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel16; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel5; private javax.swing.JSeparator jSeparator1; private javax.swing.JTextField jTextField2; private javax.swing.JPanel jbBitcoin; private javax.swing.JButton jbtnBitcoin; private javax.swing.JButton jbtnCash; private javax.swing.JButton jbtnClear; private javax.swing.JButton jbtnCreditCard; private javax.swing.JButton jbtnEnter; private javax.swing.JButton jbtnGiftCard; private javax.swing.JButton jbtnNum0; private javax.swing.JButton jbtnNum00; private javax.swing.JButton jbtnNum1; private javax.swing.JButton jbtnNum2; private javax.swing.JButton jbtnNum3; private javax.swing.JButton jbtnNum4; private javax.swing.JButton jbtnNum5; private javax.swing.JButton jbtnNum6; private javax.swing.JButton jbtnNum7; private javax.swing.JButton jbtnNum8; private javax.swing.JButton jbtnNum9; private javax.swing.JButton jbtnNumAmt10; private javax.swing.JButton jbtnNumAmt20; private javax.swing.JButton jbtnNumAmt5; private javax.swing.JButton jbtnNumAmtExact; private javax.swing.JButton jbtnNumDot; private javax.swing.JLabel jlblCardNum; private javax.swing.JLabel jlblGiftCardNum; private javax.swing.JPanel jpCash; private javax.swing.JPanel jpCreditDebit; private javax.swing.JPanel jpGift; private javax.swing.JPanel jpMethod; private javax.swing.JPanel jpPaymentInput; private javax.swing.JRadioButton jradCredit; private javax.swing.JRadioButton jradDebit; private javax.swing.JTextField jtfCardNum; private javax.swing.JTextField jtfGiftCardNum; private javax.swing.JTextField jtfNumPad; private javax.swing.JLabel lblBTCDue; private javax.swing.JLabel lblDue; private javax.swing.JLabel lblPaid; private javax.swing.JLabel lblPromo; private javax.swing.JLabel lblQRC; private javax.swing.JLabel lblSubtotal; private javax.swing.JLabel lblTax; private javax.swing.JLabel lblTimer; private javax.swing.JLabel lblTotal; private javax.swing.JLabel lblUSDtoBTC; private javax.swing.JTextField txtPayAmt; // End of variables declaration//GEN-END:variables }