ユーザーの詳細のarrayListを、作成した各ユーザーの詳細を含む別のarrayListに追加するのに苦労しています。
私は2つのクラスを持っています:addUser
とDatabase
.
addUser
クラスには、次のコードがあります。
JLabel submitButton = new JLabel("Submit: ");
contentPane.add(submitButton);
JButton addUser = new JButton("+ Add User");
addUser.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
addToArray();
databaseArray.add(app);
frame.dispose();}});
contentPane.add(addUser);
frame.pack();
frame.setVisible(true);
frame.setLocationRelativeTo(null);
}
//arraylist of details for a single applicant
final ArrayList<String> app = new ArrayList<String>();
public void addToArray()
{
appNumber = appNumberField.getText();
name = nameField.getText();
date = dateField.getText();
fileLoc = fileLocField.getText();
country = countryRefField.getText();
app.add(appNumber);
app.add(name);
app.add(date);
app.add(fileLoc);
app.add(country);
}
データベースクラスには、次のコードがあります。
public class Database
{
public ArrayList<ArrayList> applicants;
/**
* Constructor for objects of class Database
*/
public Database()
{
applicants = new ArrayList<ArrayList>();
}
/**
* adds a new applicant to the database
*/
public void addApplicant(ArrayList app)
{
applicants.add(app);
}
public void list()
{
int n = applicants.size();
for(int i = 0; i < n ; i++)
System.out.println(applicants.get(i));
}
}
ただし、クラスからユーザーを追加すると、addUser
クラスで list メソッドを使用しても表示されませんDatabase
。
どんな助けでも大歓迎です。
ありがとう。