在arraylist中使用accountno返回帐户名?我在搜索 accountno 时无法返回帐户名称。我只想当用户在帐户字段中输入帐户编号时,与该帐户编号关联的帐户名称将显示在帐户名称字段中。
private void txt_wdaccountnumberActionPerformed(java.awt.event.ActionEvent evt) {
for(BankAccount account: list){
if(account.getAccountNo().equals(txt_wdaccountnumber.getText())){
txt_wdaccountname.setText(account.getAccountName());
System.out.println(txt_wdaccountname);
return;
添加账户:
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());
account.setBalance(Double.parseDouble(txt_initialbalance.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");