-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchDialog.java
More file actions
69 lines (55 loc) · 2.32 KB
/
Copy pathSearchDialog.java
File metadata and controls
69 lines (55 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package gui;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.List;
public class SearchDialog extends JDialog {
private JTextField searchField;
private JButton searchButton;
private JTextArea resultArea;
private JComboBox<String> searchTypeComboBox;
private EmployeeManager employeeManager;
public SearchDialog(Window parent, EmployeeManager employeeManager, EmployeeTable employeeTable) {
super(parent, "Search Employee", ModalityType.APPLICATION_MODAL);
this.employeeManager = employeeManager;
setLayout(new BorderLayout());
JPanel inputPanel = new JPanel();
inputPanel.add(new JLabel("Enter Employee ID or Name:"));
searchField = new JTextField(15);
inputPanel.add(searchField);
searchTypeComboBox = new JComboBox<>(new String[]{"Linear Search", "Binary Search"});
inputPanel.add(searchTypeComboBox);
searchButton = new JButton("Search");
inputPanel.add(searchButton);
add(inputPanel, BorderLayout.NORTH);
resultArea = new JTextArea(10, 30);
resultArea.setEditable(false);
add(new JScrollPane(resultArea), BorderLayout.CENTER);
searchButton.addActionListener((ActionEvent e) -> performSearch());
setSize(400, 300);
setLocationRelativeTo(parent);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
private void performSearch() {
String searchTerm = searchField.getText().trim();
String searchType = (String) searchTypeComboBox.getSelectedItem();
List<Employee> employees = employeeManager.getAllEmployees();
List<Employee> results;
if ("Linear Search".equals(searchType)) {
results = SearchUtils.linearSearch(employees, searchTerm);
} else {
results = SearchUtils.binarySearch(employees, searchTerm);
}
displayResults(results);
}
private void displayResults(List<Employee> results) {
resultArea.setText("");
if (results == null || results.isEmpty()) {
resultArea.append("No employees found.\n");
} else {
for (Employee emp : results) {
resultArea.append(emp.toString() + "\n");
}
}
}
}