0

我有一个新的帐户框架,其中包含帐号、帐户名称、初始余额,它们存储在一个数组列表中并保存在一个文本文件中。我还有一个仅包含帐号和帐户名称的提款和存款框架。我的问题是,我如何从保存在文本文件中的 arraylist 中的新帐户获取/显示帐号、帐户名称。例如:账户名:James,账户号:201,Initialbalance:5000。在提款框架中,当我在账户号文本字段中输入账户号时,它将在保存在文本文件中的数组列表中搜索,并显示账户名在帐户名称字段中。此外,当用户尝试提取大于初始余额时,它会提示“资金不足!”。

下面是我来自新帐户的代码,我不知道如何从提款框架中获取数据。

public class JFrameNewAccount extends javax.swing.JFrame {
ArrayList<String> al = new ArrayList<String>();    

  public JFrameNewAccount() {
    initComponents();

   groupButton();


 }


private void btnCancelAActionPerformed(java.awt.event.ActionEvent evt) {                                           
        this.setVisible(false);
    }



private void btnSaveAActionPerformed(java.awt.event.ActionEvent evt) {                                         
            ButtonGroup bg = new ButtonGroup();
            bg.add(rad_savings);
            bg.add(rad_checking);
        al.add(txt_accountnumber.getText());
    al.add((txt_accountname.getText()));
    if(rad_savings.isSelected()){
            al.add(rad_savings.getText());
    }
        else{
            al.add(rad_checking.getText());
    }
        al.add(txt_initialbalance.getText());
    if(rad_savings.isSelected()){
            al.add(txt_interestrate.getText());
    }
        else{
            al.add(txt_overdraft.getText());
    }
    String fileName = "bank.txt";
        FileWriter file = null;
        try {
            file = new FileWriter(fileName,true);
            PrintWriter pw = new PrintWriter(file);
            for(String str: al) {
                pw.println(str);
            }

       pw.flush();
       pw.println("\n");
        System.out.println("Write successful...");
    } catch(FileNotFoundException ex) {
        System.out.println("File not found....");
    } catch (IOException ex) {
        Logger.getLogger(JFrameNewAccount.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
       try {
           file.close();
       } catch (IOException ex) {
           Logger.getLogger(JFrameNewAccount.class.getName()).log(Level.SEVERE, null, ex);
       }
    }
 JOptionPane.showMessageDialog(this, "Your accont has been created!");
        txt_accountname.setText("");   
        txt_accountnumber.setText("");// TODO add your handling code here:
        txt_initialbalance.setText("");
        txt_overdraft.setText("");
        txt_interestrate.setText("");
        bg.clearSelection();
        txt_accountnumber.requestFocus();




}                
4

0 回答 0