これは、従業員の情報 (給与、名前、ID 番号、雇用日) を配列リストに格納するプログラムです。('listButton' を押した後に) 呼び出されると、この情報が Field に一覧表示され、雇用主が見ることができます。従業員はリストから従業員を削除する必要があります。removeButton があります。雇用主が従業員のリストから名前を削除するにはどうすればよいでしょうか?
public class EmployeeView extends FrameView {
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;
}
}
/** Define the ArrayList */
ArrayList <Company> employee = new ArrayList <Company>();
String ID, firstName, lastName, annualSal, startDate;
public EmployeeView(SingleFrameApplication app) {
//GUI stuff...
}
private void AddActionPerformed(java.awt.event.ActionEvent evt) {
ID = IDField.getText();
firstName = firstNameField.getText();
lastName = lastNameField.getText();
annualSal = annualSalField.getText();
startDate = startDateField.getText();
Company c = new Company(ID, firstName, lastName, annualSal, startDate);
employee.add(c);
}
private void ListActionPerformed(java.awt.event.ActionEvent evt) {
String temp = "";
for (int x=0; x<=employee.size()-1; x++) {
temp = temp + employee.get(x).ID + " "
+ employee.get(x).firstName + " "
+ employee.get(x).lastName + " "
+ employee.get(x).annualSal + " "
+ employee.get(x).startDate + "\n";
}
employeeTArea.setText(temp);
}
private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {
//My attempt... it didn't do anything though
int remove = 0;
for (int j = 0; j < employee.size()-1; j++) {
if (remove == Integer.parseInt(IDField.getText())) {
employee.remove(j);
}
}
}