这是我第一次使用数组列表创建程序,我遇到了一个小问题。代码的小描述...您列出员工的信息(ID#、姓名、开始日期、薪水等),并在“employeeTArea”中输出。
public class EmployeeView extends FrameView {
/** Define the ArrayList */
ArrayList <String> inventory = new ArrayList <String>();
public EmployeeView(SingleFrameApplication app) {
}// </editor-fold>
private void AddActionPerformed(java.awt.event.ActionEvent evt) {
String c;
String ID, firstName, lastName, annualSal, startDate;
ID = IDField.getText();
firstName = firstNameField.getText();
lastName = lastNameField.getText();
annualSal = annualSalField.getText();
startDate = startDateField.getText();
c = new String (ID);
c = new String (firstName);
c = new String (lastName);
c = new String (annualSal);
c = new String (startDate);
inventory.add(c);
}
private void ListActionPerformed(java.awt.event.ActionEvent evt) {
问题就在下面……尽管在 get(x)(名字、姓氏、ID 等)带有红色下划线之后,您可能看不到所有内容。就这几个字。当然,这会产生一个问题,因为在我通过按下“addButton”将员工信息存储在数组中之后,当我按下“listButton”以显示该信息时,我将无法再访问该信息。
String temp="";
for (int x=0; x<=inventory.size()-1; x++) {
temp = temp + inventory.get(x).ID + " "
+ inventory.get(x).firstName + " "
+ inventory.get(x).lastName + " "
+ inventory.get(x).annualSal + " "
+ inventory.get(x).startDate + "\n";
}
inventoryOut.setText(temp);
class Company {
String ID, firstName, lastName, annualSal, startDate, mileage;
Company (String _ID, String _firstName,String _lastName, String _annualSal, String _startDate) {
ID = _ID;
firstName = _firstName;
lastName = _lastName;
annualSal = _annualSal;
startDate = _startDate;
}
}
}