Results 1 to 3 of 3

Thread: JFrame question

  1. #1
    Try2Live4God is offline Member
    Join Date
    Aug 2007
    Posts
    5
    Rep Power
    0

    Default JFrame question

    Again, I am new to Java. So any help would be appreciated.

    I created a basic JFrame banking system. It looks something like this:


    My question is this. If the user selects the deposit radio button, the textbox for the deposit enables. How would I then place all deposits or withdrawals that the user input in the deposit or withdrawal textbox into the list box? If someone can help me or point me in the right direction, it would be great.

    Thanks!

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Transferring data from the deposit JTextField to the deposit list.
    For each entry into the deposit textField (depositField), press the "ok" button and in the listener for the "ok" button you add the depositField entry to the list:
    Java Code:
    public void actionPerformed(ActionEvent e) {
        String text = depositField.getText();
        DefaultListModel model = (DefaultListModel)list.getModel();
        model.addElement(text);
        depositField.setText("");
    }
    To be able to make changes to the list you will need to use a DefaultListModel.
    Java Code:
    JList list = new JList(new DefaultListModel());

  3. #3
    Try2Live4God is offline Member
    Join Date
    Aug 2007
    Posts
    5
    Rep Power
    0

    Default

    Am I supposed to add this listener anywhere in the code?

    I'm not exactly sure....never dealt with listeners.....
    Here is my current code....


    Java Code:
    package CIS355.TestJFrame;
    
    import javax.swing.*;
    import java.text.DecimalFormat;
    
    
    class Customer
    {
        //      Attributes
        
        String customerName;
        int customerId;
        double accountBalance;
        double totalWithdrawals;
        double totalDeposits;
        
        //      Methods
        
        void processDeposit(double depositAmount)
        {
            accountBalance += depositAmount;
    	totalDeposits += depositAmount; 
        }
        
        boolean processWithdrawal(double withdrawalAmount)
        {
            if (withdrawalAmount <= accountBalance)
            {
                accountBalance -= withdrawalAmount;
    	    totalWithdrawals += withdrawalAmount;
                return true;
            } 
            else
            {
                String errorMessage = "Insufficient funds!! ";
                errorMessage += "Your current balance is " + accountBalance;
                JOptionPane.showMessageDialog(null, errorMessage, "Error Message 101",
                        JOptionPane.ERROR_MESSAGE);
                return false;
            }
      
        }
    
        Customer (String custName, int custID, double balance)
        {
        	this.customerName = custName;
        	this.customerId = custID;
        	this.accountBalance = balance;
    	totalDeposits = 0;
    	totalWithdrawals = 0;
        }
    }
    
    
    public class TestCustomerJFrame1 extends javax.swing.JFrame {
        
        /** Creates new form TestCustomerJFrame */
        public TestCustomerJFrame1() {
            initComponents();
        }
        
        DecimalFormat twoDigits = new DecimalFormat("0.00");
        
        /** 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.
         */
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                          
        private void initComponents() {
            lblName = new javax.swing.JLabel();
            lblID = new javax.swing.JLabel();
            lblBalance = new javax.swing.JLabel();
            txtCustName = new javax.swing.JTextField();
            txtCustID = new javax.swing.JTextField();
            txtInitBal = new javax.swing.JTextField();
            btnPress = new javax.swing.JButton();
            btnClose = new javax.swing.JButton();
            jPanel1 = new javax.swing.JPanel();
            jLabel1 = new javax.swing.JLabel();
            txtDeposit = new javax.swing.JTextField();
            btnDepOk = new javax.swing.JButton();
            jPanel2 = new javax.swing.JPanel();
            rdoDeposit = new javax.swing.JRadioButton();
            rdoWithdrawal = new javax.swing.JRadioButton();
            rdoBalance = new javax.swing.JRadioButton();
            jPanel3 = new javax.swing.JPanel();
            jLabel2 = new javax.swing.JLabel();
            txtWithdrawal = new javax.swing.JTextField();
            btnWithOk = new javax.swing.JButton();
            jScrollPane1 = new javax.swing.JScrollPane();
            lstWithdrawal = new javax.swing.JList();
            jScrollPane3 = new javax.swing.JScrollPane();
            lstDeposit = new javax.swing.JList();
            lblTotalDep = new javax.swing.JLabel();
            lblTotalWith = new javax.swing.JLabel();
            jLabel5 = new javax.swing.JLabel();
            jLabel6 = new javax.swing.JLabel();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Customer Info");
            addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    formMouseClicked(evt);
                }
            });
    
            lblName.setFont(new java.awt.Font("Arial", 1, 12));
            lblName.setText("Customer Name");
    
            lblID.setFont(new java.awt.Font("Arial", 1, 12));
            lblID.setText("Customer ID");
    
            lblBalance.setFont(new java.awt.Font("Arial", 1, 12));
            lblBalance.setText("Initial Balance");
    
            btnPress.setText("Press");
            btnPress.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    btnPressMouseClicked(evt);
                }
            });
    
            btnClose.setText("Close");
            btnClose.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    btnCloseMouseClicked(evt);
                }
            });
    
            jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Deposit Window", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 10), new java.awt.Color(51, 51, 255)));
            jPanel1.setEnabled(false);
            jLabel1.setText("Enter Amt Below");
    
            txtDeposit.setEnabled(false);
    
            btnDepOk.setText("Ok");
            btnDepOk.setEnabled(false);
            btnDepOk.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    btnDepOkMouseClicked(evt);
                }
            });
    
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(txtDeposit, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE)
                            .addContainerGap())
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(btnDepOk, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(24, 24, 24))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE)
                            .addContainerGap())))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(jLabel1)
                    .addGap(16, 16, 16)
                    .addComponent(txtDeposit, 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)
                    .addComponent(btnDepOk))
            );
    
            jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Transaction Selection", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 10), new java.awt.Color(51, 51, 255)));
            jPanel2.setEnabled(false);
            jPanel2.setOpaque(false);
            rdoDeposit.setText("Deposit");
            rdoDeposit.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
            rdoDeposit.setEnabled(false);
            rdoDeposit.setMargin(new java.awt.Insets(0, 0, 0, 0));
            rdoDeposit.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    rdoDepositMouseClicked(evt);
                }
            });
    
            rdoWithdrawal.setText("Withdrawal");
            rdoWithdrawal.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
            rdoWithdrawal.setEnabled(false);
            rdoWithdrawal.setMargin(new java.awt.Insets(0, 0, 0, 0));
            rdoWithdrawal.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    rdoWithdrawalMouseClicked(evt);
                }
            });
    
            rdoBalance.setText("Balance Inquiry");
            rdoBalance.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
            rdoBalance.setEnabled(false);
            rdoBalance.setMargin(new java.awt.Insets(0, 0, 0, 0));
            rdoBalance.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    rdoBalanceMouseClicked(evt);
                }
            });
    
            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(rdoBalance)
                        .addComponent(rdoDeposit)
                        .addComponent(rdoWithdrawal))
                    .addContainerGap(20, Short.MAX_VALUE))
            );
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(rdoDeposit, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(rdoWithdrawal)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(rdoBalance)
                    .addContainerGap())
            );
    
            jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Withdrawal Window", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 10), new java.awt.Color(51, 51, 255)));
            jPanel3.setEnabled(false);
            jLabel2.setText("Enter Amount Below");
    
            txtWithdrawal.setEnabled(false);
    
            btnWithOk.setText("Ok");
            btnWithOk.setEnabled(false);
            btnWithOk.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    btnWithOkMouseClicked(evt);
                }
            });
    
            javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
            jPanel3.setLayout(jPanel3Layout);
            jPanel3Layout.setHorizontalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(txtWithdrawal, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE))
                            .addGap(10, 10, 10))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                            .addComponent(btnWithOk, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(25, 25, 25))))
            );
            jPanel3Layout.setVerticalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addComponent(jLabel2)
                    .addGap(15, 15, 15)
                    .addComponent(txtWithdrawal, 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)
                    .addComponent(btnWithOk))
            );
    
            jScrollPane1.setViewportView(lstWithdrawal);
    
            jScrollPane3.setViewportView(lstDeposit);
    
            lblTotalDep.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    
            lblTotalWith.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
    
            jLabel5.setText("Total Deposits");
    
            jLabel6.setText("Total Withdrawals");
    
            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.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(50, 50, 50)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(lblID)
                                        .addComponent(lblBalance)
                                        .addComponent(lblName))
                                    .addGap(26, 26, 26)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel5))
                                                .addComponent(lblTotalDep, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGap(56, 56, 56)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(lblTotalWith, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel6)
                                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGap(39, 39, 39))
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(txtInitBal, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtCustID, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtCustName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE))))))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(124, 124, 124)
                            .addComponent(btnPress)
                            .addGap(41, 41, 41)
                            .addComponent(btnClose)))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addGap(33, 33, 33)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblName)
                        .addComponent(txtCustName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblID)
                        .addComponent(txtCustID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblBalance)
                        .addComponent(txtInitBal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(21, 21, 21)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnPress)
                        .addComponent(btnClose))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jScrollPane1, 0, 0, Short.MAX_VALUE)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(jLabel6))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(lblTotalDep, javax.swing.GroupLayout.DEFAULT_SIZE, 17, Short.MAX_VALUE)
                        .addComponent(lblTotalWith, javax.swing.GroupLayout.DEFAULT_SIZE, 17, Short.MAX_VALUE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap())
            );
            pack();
        }// </editor-fold>                        
    
        private void rdoBalanceMouseClicked(java.awt.event.MouseEvent evt) {                                        
    
            rdoDeposit.setEnabled(false);
            rdoWithdrawal.setEnabled(false);
            
            txtDeposit.setEnabled(false);
            btnDepOk.setEnabled(false);
            
            txtWithdrawal.setEnabled(false);
            btnWithOk.setEnabled(false);       
            
            JOptionPane.showMessageDialog(null, "Current balance: " + twoDigits.format(cust.accountBalance), "Balance", JOptionPane.INFORMATION_MESSAGE);
            rdoBalance.setSelected(false);
            
            txtWithdrawal.setEnabled(false);
            btnWithOk.setEnabled(false);
            txtDeposit.setEnabled(false);
            btnDepOk.setEnabled(false);
            rdoWithdrawal.setEnabled(true);
            rdoDeposit.setEnabled(true);
            rdoBalance.setEnabled(true);
        }                                       
    
        private void rdoWithdrawalMouseClicked(java.awt.event.MouseEvent evt) {                                           
    
            rdoDeposit.setEnabled(false);
            rdoBalance.setEnabled(false);
            
            txtWithdrawal.setEnabled(true);
            btnWithOk.setEnabled(true);
            rdoWithdrawal.setEnabled(false);
            
        }                                          
    
        private void rdoDepositMouseClicked(java.awt.event.MouseEvent evt) {                                        
    
            rdoWithdrawal.setEnabled(false);
            rdoBalance.setEnabled(false);
            
            txtDeposit.setEnabled(true);
            btnDepOk.setEnabled(true);
            rdoDeposit.setEnabled(false);
        }                                       
    
        private void btnWithOkMouseClicked(java.awt.event.MouseEvent evt) {                                       
    
            rdoWithdrawal.setSelected(false);
            withAmount = Double.parseDouble(txtWithdrawal.getText());
            cust.processWithdrawal(withAmount);
            
            txtInitBal.setText(String.valueOf(cust.accountBalance));
            
            txtWithdrawal.setEnabled(false);
            btnWithOk.setEnabled(false);
            
            rdoDeposit.setEnabled(true);
            rdoWithdrawal.setEnabled(true);
            rdoBalance.setEnabled(true);
            txtWithdrawal.setText("");
            
            lblTotalWith.setText(String.valueOf(cust.totalWithdrawals));
            
        }                                      
    
        private void btnDepOkMouseClicked(java.awt.event.MouseEvent evt) {                                      
    
            rdoDeposit.setSelected(false);
            depAmount = Double.parseDouble(txtDeposit.getText());
            cust.processDeposit(depAmount);
            
            txtInitBal.setText(String.valueOf(cust.accountBalance));
            
            
            rdoDeposit.setEnabled(true);
            rdoWithdrawal.setEnabled(true);
            rdoBalance.setEnabled(true);
            txtDeposit.setText("");
            txtDeposit.setEnabled(false);
            btnDepOk.setEnabled(false);
            
            lblTotalDep.setText(String.valueOf(cust.totalDeposits));
            
        }                                     
    
        private void btnCloseMouseClicked(java.awt.event.MouseEvent evt) {                                      
    
            this.dispose();
            
        }                                     
    
        private void btnPressMouseClicked(java.awt.event.MouseEvent evt) {                                      
    
            String output = "";
    
            if(txtCustName.getText().equals(""))
            {
                JOptionPane.showMessageDialog(null, "Invalid Name", "Error", JOptionPane.ERROR_MESSAGE);
            } 
            
            else if(txtCustID.getText().equals(""))
            {
                JOptionPane.showMessageDialog(null, "Invalid ID", "Error", JOptionPane.ERROR_MESSAGE);
            }
            
            else if(txtInitBal.getText().equals(""))
            {
                JOptionPane.showMessageDialog(null, "Invalid Balance", "Error", JOptionPane.ERROR_MESSAGE);
            }
    
            else 
            {
                custName = txtCustName.getText();
                custID = Integer.parseInt(txtCustID.getText());
                balance = Double.parseDouble(txtInitBal.getText());
                output = "Customer Name: " + custName + "\n";
                output += "Customer ID: " + custID + "\n";
                output += "Customer Balance: " + twoDigits.format(balance);
                JOptionPane.showMessageDialog(null, output, "Customer Info", JOptionPane.INFORMATION_MESSAGE);
                
                cust = new Customer(custName, custID, balance);
                
                rdoDeposit.setEnabled(true);
                rdoWithdrawal.setEnabled(true);
                rdoBalance.setEnabled(true);
                
                lblBalance.setText("Current Balance");
            }
    
     
        }                                     
    
        private void formMouseClicked(java.awt.event.MouseEvent evt) {                                  
        //non functional
        }                                 
        
    
        
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new TestCustomerJFrame1().setVisible(true);
                }
            });
        }
        
        // Variables declaration - do not modify                     
        private javax.swing.JButton btnClose;
        private javax.swing.JButton btnDepOk;
        private javax.swing.JButton btnPress;
        private javax.swing.JButton btnWithOk;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JLabel jLabel6;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JPanel jPanel3;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JScrollPane jScrollPane3;
        private javax.swing.JLabel lblBalance;
        private javax.swing.JLabel lblID;
        private javax.swing.JLabel lblName;
        private javax.swing.JLabel lblTotalDep;
        private javax.swing.JLabel lblTotalWith;
        private javax.swing.JList lstDeposit;
        private javax.swing.JList lstWithdrawal;
        private javax.swing.JRadioButton rdoBalance;
        private javax.swing.JRadioButton rdoDeposit;
        private javax.swing.JRadioButton rdoWithdrawal;
        private javax.swing.JTextField txtCustID;
        private javax.swing.JTextField txtCustName;
        private javax.swing.JTextField txtDeposit;
        private javax.swing.JTextField txtInitBal;
        private javax.swing.JTextField txtWithdrawal;
        // End of variables declaration                   
        
        String custName;
        int custID;
        double balance;
        double depAmount;
        double withAmount;
        Customer cust;
        
    }

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM
  2. JFrame Question ?
    By Mindhunter74 in forum New To Java
    Replies: 2
    Last Post: 12-21-2007, 10:45 PM
  3. How to close a JFrame
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 05:33 PM
  4. JFrame vs Applet
    By baltimore in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 03:24 AM
  5. Help with JFrame
    By Albert in forum AWT / Swing
    Replies: 2
    Last Post: 07-04-2007, 04:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •