i have a new account frame which consist of account number, account name, initialbalance which store in a arraylist and saved in a textfile.. and i also have a withdraw and deposit frame which consist only of account number and account name.. My problem is, how do i get/display the account number, account name, from the the new account from the arraylist that save in a textfile. For ex: Account name: James, Account number: 201, Initialbalance: 5000. In the Withdraw frame, when i input the Account number in account number textfield, it will search in the arraylist that saved in the textfile, and display the account name in the account name field. Also, when user try to withdraw greater that the initialbalance, it will message 'insufficient funds!'.
Below is my code from New Account and I don't know how i will get the data from it from the withdraw frame.
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();
}