Как я могу получить доступ к arraylist из любого места в моем проекте и взаимодействовать только с одним объектом в нем - PullRequest
1 голос
/ 02 марта 2020

У меня есть задание сделать gui для банковского приложения с 5 функциями баланса, снятия, депозита, выхода и для создания нового клиента. У меня было 2 класса сначала BankAccount и Customer. Я сделал jframe windows для gui, но я застрял, я не знаю, как заставить работать функции пополнения, снятия и баланса. Я хочу, чтобы пользователь ввел номер своей учетной записи, и на основании этого я вызываю его учетную запись со своим балансом и позволяю ему вносить / снимать средства и получать баланс, Idk знает, как этого добиться. * Созданные заказчиком объекты хранятся в массиве (одно из требований для назначения).

//MainPage gui
private void NCustBtnActionPerformed(java.awt.event.ActionEvent evt) {                                         
          NewCustomer Nmenu = new NewCustomer();
          Nmenu.setVisible(true);
    }                                        

    private void DepositBtnActionPerformed(java.awt.event.ActionEvent evt) {                                           
          Deposit D=new Deposit();
          D.setVisible(true);


    }                                          

    private void ExtBtnActionPerformed(java.awt.event.ActionEvent evt) {                                       
       System.exit(0);
    }                                      

    private void WithdrawBtnActionPerformed(java.awt.event.ActionEvent evt) {                                            
         Withdraw T=new Withdraw();
          T.setVisible(true);
    }                                           

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainPage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainPage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainPage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainPage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>
       MainPage Menu= new MainPage();
       Menu.setVisible(true);
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainPage().setVisible(true);
            }
        });
    }


    private javax.swing.JButton BalBtn;
    private javax.swing.JButton DepositBtn;
    private javax.swing.JButton ExtBtn;
    private javax.swing.JPanel HeadingPanel;
    private javax.swing.JButton NCustBtn;
    private javax.swing.JButton WithdrawBtn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration                   
}
//BankAccount Class
public class BankAccount {

    private int accountNumber;
    private double balance;

    public BankAccount(int randnum1) {
        accountNumber = randnum1;
        balance = 0;
    }

    public BankAccount(int randnum1, double randNum2) {
        accountNumber = randnum1;
        balance = randNum2;
    }

    public int getAccountNumber() {

        return accountNumber;
    }


    public double getBalance() {
        return balance;
    }


    public void deposit(double amt) {
        balance = balance + amt;
    }


    public String withdraw(double amt) {
        String result = "";

        if (amt <= balance) {
            balance = balance - amt;

            result = "Your balance is " + balance;
            return result;
        } else if (amt > balance) {
            result = ("You have insufficient funds to withdraw this amount");

        }
        return result;
    }

}


public class Customer {
    //Class attribute
    private String firstName;
    private String lastName;
    private BankAccount account;
    private String Month;
    private String Day;
    private String Year;
   ArrayList<Customer> CustomerList=new ArrayList<Customer>();
    //Constructor
    Customer(String fName, String lName){
        firstName=fName;
        lastName=lName;

    }
    //Overloaded Constructor
    Customer(String fName, String lName, BankAccount acc1)
    {
        firstName=fName;
        lastName=lName;
        account=acc1;
    }
    Customer(String fName, String lName, BankAccount acc1,String month,String day,String year)
    {
        firstName=fName;
        lastName=lName;
        account=acc1;
        Day=day;
        Month=month;
        Year=year;

    }


    public String getDay() {
        return Day;
    }
    public void setDay(String day )
    {
        this.Day=day;
    }

    public String getMonth() {
        return Month;
    }

    public void setMonth(String month) {
        Month = month;
    }
    public String getYear()
    {
        return Year;
    }

    public void setYear(String year) {
        Year = year;
    }

    //Accessor to retrieve User's first name
    public String getFirstName()
    {
        return firstName;
    }

    //Mutator to set user entered information as first name
    public void setFirstName(String fName)
    {
        this.firstName=fName;
    }


    public String getLastNameName()
    {
        return lastName;
    }


    //Mutator to set user entered information as last name
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    //Accessor to retrieve account information
    public BankAccount getAccount() {
        return account;
    }
//Mutator for BankAccount object
    public void setAccount(BankAccount account) {
        this.account = account;
    }
}

//Gui that allows user to register as new customer
public class NewCustomer extends javax.swing.JFrame {

    /**
     * Creates new form NewCustomer
     */
    public NewCustomer() {
        initComponents();
    }

    /**
     * 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">                          
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        FnameLbl = new javax.swing.JLabel();
        LnameTxt = new javax.swing.JTextField();
        LnameLBl = new javax.swing.JLabel();
        FnameTxt1 = new javax.swing.JTextField();
        RegLbl = new javax.swing.JLabel();
        RegisterBtn = new javax.swing.JButton();
        DOBLbl = new javax.swing.JLabel();
        DOBMonth = new javax.swing.JComboBox<>();
        DOBDay = new javax.swing.JComboBox<>();
        DoBYearTxt = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        TextArea = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(51, 255, 255));

        FnameLbl.setFont(new java.awt.Font("Onyx", 0, 24)); // NOI18N
        FnameLbl.setText("First Name");

        LnameLBl.setFont(new java.awt.Font("Onyx", 0, 24)); // NOI18N
        LnameLBl.setText("Last Name");

        RegLbl.setFont(new java.awt.Font("Onyx", 0, 36)); // NOI18N
        RegLbl.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        RegLbl.setText("Registration");

        RegisterBtn.setFont(new java.awt.Font("Onyx", 0, 24)); // NOI18N
        RegisterBtn.setText("GENERATE");
        RegisterBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RegisterBtnActionPerformed(evt);
            }
        });

        DOBLbl.setFont(new java.awt.Font("Onyx", 0, 24)); // NOI18N
        DOBLbl.setText("Date Of Birth");

        DOBMonth.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "January", "Februrary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }));
        DOBMonth.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DOBMonthActionPerformed(evt);
            }
        });

        DOBDay.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", " " }));
        DOBDay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DOBDayActionPerformed(evt);
            }
        });

        DoBYearTxt.setText("Year");
        DoBYearTxt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DoBYearTxtActionPerformed(evt);
            }
        });

        TextArea.setColumns(20);
        TextArea.setRows(5);
        jScrollPane1.setViewportView(TextArea);

        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.TRAILING)
                    .addComponent(RegLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(FnameLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(LnameLBl, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(DOBLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(32, 32, 32)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(FnameTxt1, javax.swing.GroupLayout.DEFAULT_SIZE, 190, Short.MAX_VALUE)
                                .addComponent(LnameTxt))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(RegisterBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(DOBMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(DOBDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(18, 18, 18)
                                .addComponent(DoBYearTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(132, Short.MAX_VALUE))
            .addComponent(jScrollPane1)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(RegLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(FnameLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(FnameTxt1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(LnameTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LnameLBl, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(DOBLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(DOBMonth, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(DOBDay, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(DoBYearTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(RegisterBtn)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>                        
ArrayList<Customer> CustomerList=new ArrayList<Customer>();
    private void RegisterBtnActionPerformed(java.awt.event.ActionEvent evt) {                                            
        String fName=FnameTxt1.getText();
        String lName=LnameTxt.getText();
        Random rand = new Random();
        String mont= DOBMonth.getSelectedItem().toString();
        String day=DOBDay.getSelectedItem().toString();
        String year=DoBYearTxt.getText();



        int randnum1 = rand.nextInt(9000000);
        Double IntBal=500.00;
        BankAccount account1 = new BankAccount(randnum1, IntBal);
        Customer customer1=new Customer(fName,lName,account1,mont,day,year);
        CustomerList.add(customer1);


        TextArea.append("Thank you for registering with Dior Bank "+"" + fName +" "+ lName +" "+ "\n Your account number is" + " "+ randnum1);

    }                                           




    private void DOBMonthActionPerformed(java.awt.event.ActionEvent evt) {                                         
     String mont= DOBMonth.getSelectedItem().toString();
    }                                        

    private void DOBDayActionPerformed(java.awt.event.ActionEvent evt) {                                       
        String day=DOBDay.getSelectedItem().toString();
    }                                      

    private void DoBYearTxtActionPerformed(java.awt.event.ActionEvent evt) {                                           
        String year=DoBYearTxt.getText();
    }                                          

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(NewCustomer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NewCustomer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NewCustomer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NewCustomer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewCustomer().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JComboBox<String> DOBDay;
    private javax.swing.JLabel DOBLbl;
    private javax.swing.JComboBox<String> DOBMonth;
    private javax.swing.JTextField DoBYearTxt;
    private javax.swing.JLabel FnameLbl;
    private javax.swing.JTextField FnameTxt1;
    private javax.swing.JLabel LnameLBl;
    private javax.swing.JTextField LnameTxt;
    private javax.swing.JLabel RegLbl;
    private javax.swing.JButton RegisterBtn;
    private javax.swing.JTextArea TextArea;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration                   
}

//This is where im stuck this is the window i want to asked the user for their account number but i dont know how to achieve this 

 public Transaction( ) {
        initComponents();

    }
 Transaction (BankAccount acc1,ArrayList CustomerList,Integer accNum)
 {
     Acc1=acc1;
     CustList=CustomerList;
     accountNumber=accNum;

 }

    /**
     * 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">                          
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        AccNumTxt = new javax.swing.JTextField();
        AccBtn = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(0, 255, 255));

        jLabel1.setFont(new java.awt.Font("Onyx", 0, 24)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Please Enter your Account Number");

        AccBtn.setFont(new java.awt.Font("Onyx", 0, 24)); // NOI18N
        AccBtn.setText("Enter");
        AccBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AccBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(115, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(AccNumTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(104, 104, 104))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(AccBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(151, 151, 151))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(AccNumTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addComponent(AccBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 86, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>                        

    private void AccBtnActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
         Integer accountNumber=Integer.parseInt(AccNumTxt.getText());
         for(Object o: CustomerList){
    }                                      

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Transaction.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Transaction.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Transaction.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Transaction.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Transaction().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
        private javax.swing.JButton AccBtn;
        private javax.swing.JTextField AccNumTxt;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JPanel jPanel1;
        // End of variables declaration                   
    }

1 Ответ

0 голосов
/ 02 марта 2020

Многие вещи не принимаются во внимание для банковского приложения. Тем не менее, я оставляю это в стороне, так как не знаю о масштабах вашего назначения.

С самого начала, если параллельные операции разрешены на конкретном банковском счете, такие как снятие и внесение могут происходить вместе или параллельно, вам следует рассмотреть возможность использования структуры данных, которая поддерживает многопоточность и может работать синхронизированным образом. Хотя arraylist не выглядит правильной структурой данных, тем не менее, если вы настаиваете на ее использовании, попробуйте использовать copyOnWriteArrayList вместо ArrayList, а в случае, если вы решите использовать карты для более быстрых операций - используйте concurrentHashMap.

Если вы Столкнувшись с проблемой видимости, вы можете добавить в свой список Publi c getters / setters.

...