Background: Im creating this Employee Records application, where you can add a persons ID, First Name, Last Name, Salary and Start Date. It consists of a "Add" button, "Remove" button, "List" Combo box, and an output.
What I need help with is sorting the arrayList by ID and displaying the sorted version in the output. `public class EmployeeRecordsView extends FrameView{
ArrayList <one> myList = new ArrayList <one>();
//List<one> records = new ArrayList<one>();
String iD, first, last, salary, startDate;
public EmployeeRecordsView(SingleFrameApplication app) {
//Cut out code
}
class one {
String iD, first, last, salary, startDate;
one (String _iD, String _first, String _last, String _salary, String
_startDate){
iD = _iD;
first = _first;
last = _last;
salary = _salary;
startDate = _startDate;
}
}
private void btnAddMouseClicked(java.awt.event.MouseEvent evt) {
one emp;
iD = id.getText();
first = firstName.getText();
last = lastName.getText();
salary = sal.getText();
startDate = start.getText();
emp = new one(iD, first, last, salary, startDate);
myList.add(emp);
}
private void btnRemoveMouseClicked(java.awt.event.MouseEvent evt) {
String remove;
remove = id.getText();
myList.remove(remove);
}
private void btnExitMouseClicked(java.awt.event.MouseEvent evt) {
System.exit(0);
}
private void jComboBox1MouseClicked(java.awt.event.MouseEvent evt) {
if (jComboBox1.getSelectedItem() == "Order of Addition"){
String temp="";
for (int x=0; x<=myList.size()-1; x++) {
temp = temp + "ID#: " + myList.get(x).iD + ", "
+ "First Name: " + myList.get(x).first + ", "
+ "Last Name: " + myList.get(x).last + ", "
+ "Annual Salary: " + myList.get(x).salary + ", "
+ "Starting Date: " + myList.get(x).startDate + "\n";
}
outPut.setText(temp);
}
if (jComboBox1.getSelectedItem() == "ID"){
String temp="";
for (int x=0; x<=myList.size()-1; x++) {
temp = temp + "ID#: " + myList.get(x).iD + ", "
+ "First Name: " + myList.get(x).first + ", "
+ "Last Name: " + myList.get(x).last + ", "
+ "Annual Salary: " + myList.get(x).salary + ", "
+ "Starting Date: " + myList.get(x).startDate + "\n";
}
outPut.setText(temp);
}`
}
Collections.sort(List, Comparator)ActionListenerfor buttons, notMouseListener, as these will be notified when the user presses [Enter] (and on some look and feels [Space]) as will as when the click it with the mouse