我有这个按钮,可以通过 ArrayLists 中的文本字段保存输入数据并将其保存到文件中。
private void btnSaveAActionPerformed(java.awt.event.ActionEvent evt) {
BankAccount account = new BankAccount();
ButtonGroup bg = new ButtonGroup();
bg.add(rad_savings);
bg.add(rad_checking);
account.setAccountName(txt_accountname.getText());
account.setAccountNo(txt_accountnumber.getText());
list.add(account);
String fileName = "bank.txt";
FileWriter file = null;
try {
file = new FileWriter(fileName,true);
PrintWriter pw = new PrintWriter(file);
for(BankAccount str: list) {
pw.println(str);
}
pw.flush();
pw.println("\n");
} catch(FileNotFoundException ex) {
JOptionPane.showMessageDialog(this, "Can't create your account!");
} 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);
}
}
我还有一个 Withdraw_AccountName 和 Withdraw_AccountNumber 的文本字段,我如何在数组列表中搜索帐号?当Withdraw_AccountNumber 与arraylists 中的账号匹配时,也会在Withdraw_AccountName 中显示账户名。请帮忙。