-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathController.java
49 lines (40 loc) · 1.17 KB
/
Controller.java
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
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
/**
* @author ashraf
*
*/
public class Controller implements ActionListener {
private JTextField searchTermTextField = new JTextField(26);
private DefaultTableModel model;
public Controller(JTextField searchTermTextField, DefaultTableModel model) {
super();
this.searchTermTextField = searchTermTextField;
this.model = model;
}
@Override
public void actionPerformed(ActionEvent e) {
String searchTerm = searchTermTextField.getText();
if (searchTerm != null && !"".equals(searchTerm)) {
Object[][] newData = new Object[Constants.DATA.length][];
int idx = 0;
for (Object[] o: Constants.DATA) {
if ("*".equals(searchTerm.trim())) {
newData[idx++] = o;
} else {
if(String.valueOf(o[0]).startsWith(searchTerm.toUpperCase().trim())){
newData[idx++] = o;
}
}
}
model.setDataVector(newData, Constants.TABLE_HEADER);
} else {
JOptionPane.showMessageDialog(null,
"Search term is empty", "Error",
JOptionPane.ERROR_MESSAGE);
}
}
}