Netbeans, Java Application (Very Urgent) Programming
Search Illustration and exampleSearch Illustration and example
1. Use enters last name 2. User hits find button 3. MainJFrame captures push
button event 4 MainJframew extracts text fromEmployee getFirstName()
1
4. MainJframew extracts text from employeelasname textfield
5. MainJFrame uses the employeedirectory to find the employee object that matches the entered last name
6 The findEmpoyee Jpanel takes
Employee.getFirstName() Employee.getLasName() :
LastnameTextfield getText()
2 6. The findEmpoyee Jpanel takes
an employee object as input. In the constructor we map the attributes of the employee object to the text fields of the jpanel. We use setText() method on the text fi ldLastnameTextfield.getText()
4 3 6
fields
employeedirectory.findByLastName( )5 This section of code is the actionperformed event in the MainJFrame
: Display employee data into findEmployeejpanel screen
Found employee object
Returned employee object
findEmployeeByLastName Method
Add the following method to the EmployeeDirectory class
Public Employee findEmployeeByLastName( String ln ){
ArrayList employeelist; //define a new reference variable to hold the list of employees
Employeelist = employeedirectory.getEmployeeList(); // retrieve the list of employees from the direcoty
//now go through the list, one employee at the time to find the object that has a last name that matches the input ln //if there is a match on the last name attribute then return the employee object with that attribute (last name in this//if there is a match on the last name attribute then return the employee object with that attribute (last name in this //case
For (Employee currentemployee : employeelist){ If (currentemployee getLastName() equals(ln) ) return currentemployee ;If (currentemployee .getLastName().equals(ln) ) return currentemployee ;
} // keep going back while there is no match
Return null; // the program gets to this line if no mtach was found which means return null;