0

我有一个 BankAccount 类,它由 accountNo 和 accountName 的“Getter and Setter”组成。另外,我有一个 JFrameNewAccount,它将添加新帐户并将其保存在 ArrayLists 中。输入将来自文本字段和单选按钮。

在我的 JFrameNewAccount 中,我有一个方法:

ArrayList<BankAccount> list = new ArrayList<BankAccount>();

在 btnSaveActionPerformed 事件中,我有这个:

list.add(txt_accountnumber.getText());
list.add((txt_accountname.getText()));

它给了我一个错误'没有找到适合 add(String) 的方法'我知道这是因为 ArrayList,如果我使用 ArrayList,它似乎还可以,但我不知道如何调用帐号我的退出框架。

4

2 回答 2

4

Your list does'nt allow you to add Strings in it.

I guess, you need to prepare an object there with the values coming from the textfields.

BankAccount account= new BankAccount();
account.setAccountnumber(txt_accountnumber.getText());
account.setAccountname(txt_accountname.getText());
list.add(account);

Each time a new user entered the Details create one object and save into the list.

于 2013-05-29T04:29:04.530 回答
1

Your ArrayList of type BankAccount

ArrayList<BankAccount> list = new ArrayList<BankAccount>();  

So you have to create a BankAccount and then save it to List:

BankAccount acc= new BankAccount();
acc.setAccountnumber(txt_accountnumber.getText());
acc.setAccountname(txt_accountname.getText());
list.add(acc);

For getting it simply get BankAccount from list like:

BankAccount acc = list.get(1); 
于 2013-05-29T04:31:24.823 回答