调用 ArrayLists 中的 accountNo、accountName [英] Calling accountNo, accountName in ArrayLists
问题描述
我有一个 BankAccount 类,它由 accountNo 和 accountName 的Getter 和 Setter"组成.另外,我有一个 JFrameNewAccount,它将添加新帐户并将其保存在 ArrayLists 中.输入将来自文本字段和单选按钮.
i have a class BankAccount, which compose of 'Getter and Setter' of accountNo and accountName. Also, I have a JFrameNewAccount which will add new accounts and save it in a ArrayLists. Inputs will be coming from textfields and radiobuttons.
在我的 JFrameNewAccount 中,我有一个方法:
In my JFrameNewAccount, i have a method:
ArrayList<BankAccount> list = new ArrayList<BankAccount>();
在 btnSaveActionPerformed 事件中,我有这个:
In, btnSaveActionPerformed event I have this:
list.add(txt_accountnumber.getText());
list.add((txt_accountname.getText()));
它给了我一个错误没有找到适合 add(String) 的方法"我知道是ArrayList的原因,如果我用ArrayList,好像还可以,但是我不知道如何调用提款框里的账号.
and it gives me an error 'No suitable method found for add(String)' I know it is because of the ArrayList, and if I used ArrayList, it seems okay, but i don't know how can i call the account number in my withdraw frame.
推荐答案
您的 list
不允许您在其中添加字符串.
Your list
does'nt allow you to add Strings in it.
我想,您需要在那里准备一个对象,其中包含来自 textfields
的值.
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);
每次新用户进入详细信息创建一个对象并保存到list
.
Each time a new user entered the Details create one object and save into the list
.
这篇关于调用 ArrayLists 中的 accountNo、accountName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!