From 70110cb787255cf6cfdfd40255e6b2015b23d08d Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Wed, 28 Feb 2024 00:56:16 +0800 Subject: [PATCH] repair payment form + add functionality must be fully working --- .../tech/iBeans/POSware/Lite/OnPayment.form | 79 +++++--- .../tech/iBeans/POSware/Lite/OnPayment.java | 176 +++++++++++++++--- 2 files changed, 201 insertions(+), 54 deletions(-) diff --git a/src/main/java/tech/iBeans/POSware/Lite/OnPayment.form b/src/main/java/tech/iBeans/POSware/Lite/OnPayment.form index 1c7ea9c..1f6071a 100644 --- a/src/main/java/tech/iBeans/POSware/Lite/OnPayment.form +++ b/src/main/java/tech/iBeans/POSware/Lite/OnPayment.form @@ -1,6 +1,14 @@ -
+ + + + + + + + + @@ -16,29 +24,6 @@ - - - - - - - - - - - - - - - - - - - - - - - @@ -80,7 +65,7 @@ - + @@ -95,6 +80,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/tech/iBeans/POSware/Lite/OnPayment.java b/src/main/java/tech/iBeans/POSware/Lite/OnPayment.java index 9d7203f..4741e9f 100644 --- a/src/main/java/tech/iBeans/POSware/Lite/OnPayment.java +++ b/src/main/java/tech/iBeans/POSware/Lite/OnPayment.java @@ -1,52 +1,54 @@ /* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license - * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JPanel.java to edit this template + * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JDialog.java to edit this template */ package tech.iBeans.POSware.Lite; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.SpinnerNumberModel; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + /** * * @author eleven */ -public class OnPayment extends javax.swing.JPanel { +public class OnPayment extends javax.swing.JDialog { /** - * Creates new form OnPayment + * Creates new form Window_Payment */ - public OnPayment() { + public OnPayment(java.awt.Frame parent, boolean modal) { + super(parent, modal); initComponents(); } + + private static OnPayment dialog_payment = new OnPayment(new javax.swing.JFrame(), true); /** * 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") + // //GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; - jPanel_actions = new javax.swing.JPanel(); - jButton_action_cancel = new javax.swing.JButton(); - jButton_action_continue = new javax.swing.JButton(); jPanel_information = new javax.swing.JPanel(); jLabel_information_total = new javax.swing.JLabel(); jTextField_information_total_value = new javax.swing.JTextField(); jLabel_information_payment_value = new javax.swing.JLabel(); jSpinner_information_payment_value = new javax.swing.JSpinner(); + jLabel_information_change = new javax.swing.JLabel(); + jTextField1 = new javax.swing.JTextField(); + jPanel_actions = new javax.swing.JPanel(); + jButton_action_cancel = new javax.swing.JButton(); + jButton_action_continue = new javax.swing.JButton(); - setLayout(new java.awt.BorderLayout()); - - jButton_action_cancel.setText("Cancel"); - jButton_action_cancel.setActionCommand("action_cancel"); - jPanel_actions.add(jButton_action_cancel); - - jButton_action_continue.setText("Complete"); - jButton_action_continue.setActionCommand("action_continue"); - jPanel_actions.add(jButton_action_continue); - - add(jPanel_actions, java.awt.BorderLayout.PAGE_END); + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle("POSware Lite: Payment"); jPanel_information.setLayout(new java.awt.GridBagLayout()); @@ -70,7 +72,7 @@ public class OnPayment extends javax.swing.JPanel { gridBagConstraints.weightx = 1.0; jPanel_information.add(jTextField_information_total_value, gridBagConstraints); - jLabel_information_payment_value.setText("jLabel1"); + jLabel_information_payment_value.setText("Payment"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; @@ -80,20 +82,136 @@ public class OnPayment extends javax.swing.JPanel { gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; + jSpinner_information_payment_value.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + getCompletable(); + } + }); + jSpinner_information_payment_value.setModel(model_price); jPanel_information.add(jSpinner_information_payment_value, gridBagConstraints); - add(jPanel_information, java.awt.BorderLayout.CENTER); + jLabel_information_change.setText("Change"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 2; + jPanel_information.add(jLabel_information_change, gridBagConstraints); + + jTextField1.setEditable(false); + jTextField1.setHorizontalAlignment(javax.swing.JTextField.TRAILING); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 2; + gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; + gridBagConstraints.weightx = 1.0; + jPanel_information.add(jTextField1, gridBagConstraints); + + getContentPane().add(jPanel_information, java.awt.BorderLayout.CENTER); + + jButton_action_cancel.setText("Cancel"); + jButton_action_cancel.addActionListener(setCancelled); + jPanel_actions.add(jButton_action_cancel); + + jButton_action_continue.setText("Complete"); + jButton_action_continue.addActionListener(setCompleted); + jPanel_actions.add(jButton_action_continue); + + getContentPane().add(jPanel_actions, java.awt.BorderLayout.PAGE_END); + + pack(); }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton_action_cancel; - private javax.swing.JButton jButton_action_continue; - private javax.swing.JLabel jLabel_information_payment_value; - private javax.swing.JLabel jLabel_information_total; - private javax.swing.JPanel jPanel_actions; - private javax.swing.JPanel jPanel_information; - private javax.swing.JSpinner jSpinner_information_payment_value; - private javax.swing.JTextField jTextField_information_total_value; + private static javax.swing.JButton jButton_action_cancel; + private static javax.swing.JButton jButton_action_continue; + private static javax.swing.JLabel jLabel_information_change; + private static javax.swing.JLabel jLabel_information_payment_value; + private static javax.swing.JLabel jLabel_information_total; + private static javax.swing.JPanel jPanel_actions; + private static javax.swing.JPanel jPanel_information; + private static javax.swing.JSpinner jSpinner_information_payment_value; + private static javax.swing.JTextField jTextField1; + private static javax.swing.JTextField jTextField_information_total_value; // End of variables declaration//GEN-END:variables + + public static Boolean display() { + /* Display the transaction. */ + dialog_payment.setModal(true); + dialog_payment.addWindowListener(new java.awt.event.WindowAdapter() { + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + // Reflect a cancelled payment. + payment.state = false; + e.getWindow().dispose(); + } + }); + getCompletable(); + dialog_payment.setVisible(true); + return(payment.state); + }; + + // Set the numerical model. + private SpinnerNumberModel model_price = new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, .01); + + // Window events + private static void getCompletable() { + float in = Float.parseFloat(String.valueOf(jSpinner_information_payment_value.getValue())); + + // Calculate the value. + payment.calculate(in); + setCompletable(); + update(); + } + + private static boolean setCompletable() { + /* Calculate whether the change is sufficient. */ + setCompletable(payment.OK); + + return (payment.OK); + }; + + private static boolean setCompletable(boolean STATE) { + /* Calculate whether the change is sufficient. */ + jButton_action_continue.setEnabled(STATE); + + if (STATE) { + dialog_payment.getRootPane().setDefaultButton(jButton_action_continue); + } else { + dialog_payment.getRootPane().setDefaultButton(jButton_action_cancel); + }; + + return (STATE); + }; + + ActionListener setCompleted = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + payment.OK = true; + payment.state = true; + dispose(); + }; + }; + + ActionListener setCancelled = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + payment.OK = false; + payment.state = false; + dispose(); + }; + }; + + + // Update information. + public static void update() { + /* Update the information. */ + if (payment.total != null) { + jTextField_information_total_value.setText(String.valueOf(payment.total)); + }; + if (payment.change != null) { + jTextField1.setText(String.valueOf(payment.change)); + }; + }; + }