因此,arrayLists 对我来说是第一个,据我所知,我所做的一切都是正确的,并遵循我的在线课程提供给我的示例。但是,由于某种原因或其他原因,我有一条红色下划线……我将在对该程序进行简要说明后立即了解。
该程序允许您输入员工信息,然后在按下“列表”按钮(listButton)后,它会在employeeField 等中输出。这基本上总结了这个程序。
public class EmployeeView extends FrameView {
class Company { //this is the class to allow me to put 'company' in the arrayList...
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;
}
}
/** Define the ArrayList */
ArrayList <Company> inventory = new ArrayList <Company>();
private void AddActionPerformed(java.awt.event.ActionEvent evt) {
String c;
String ID, firstName, lastName, annualSal, startDate;
ID = IDField.getText(); //all this stuff grabs info from the Fields...which will then be stored in the array
firstName = firstNameField.getText();
lastName = lastNameField.getText();
annualSal = annualSalField.getText();
startDate = startDateField.getText();
这下面的两行是罪魁祸首。我想“新”不是必需的,但它在示例中,所以这就是我使用它的原因......但是当我摆脱它时,只有“公司”加下划线,第二行中的“c”是下划线,而不是让整行下划线。无论如何,我希望这是有道理的......因为它(据我所知)是我唯一的问题。
c = new Company(ID, firstName, lastName, annualSal, startDate);
inventory.add(c);
}
private void ListActionPerformed(java.awt.event.ActionEvent evt) {
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";
}
employeeTArea.setText(temp);
}