Tryin to sort a search method for abit of code. Have an array list reading from a csv. Any help on how I can get a search method searching through and displaying onto a jTextArea? This is my code in my Gui
public class DataGUI extends javax.swing.JFrame {
public class DataGUI extends javax.swing.JFrame {
/**
* Creates new form DataGUI
*/
ArrayList<Bmx> people;
public int count = 0;
DefaultTableModel tableModel = new DefaultTableModel(
new Object[][]{}, new String[]{
"Rank", "First Name", "Last Name", "Uni Code", "Country", "Time"
});
public DataGUI(ArrayList<Bmx> people) {
initComponents();
this.people = people;
drawTable();
jTable1.setModel(tableModel);
jTable1.setAutoCreateRowSorter(true);
}
public void drawTable() {
tableModel.setRowCount(0);
for (int i = 0; i < people.size(); i++) {
Object[] object = new Object[9];
object[0] = people.get(i).getRank();
object[1] = people.get(i).getFirstName();
object[2] = people.get(i).getLastName();
object[3] = people.get(i).getUciCode();
object[4] = people.get(i).getCountry();
object[5] = people.get(i).getTime();
tableModel.addRow(object);
}
}
public void dataShow() {
jTextField1.setText("" + people.get(count).getRank());
jTextField2.setText("" + people.get(count).getFirstName());
jTextField3.setText("" + people.get(count).getLastName());
jTextField5.setText("" + people.get(count).getUciCode());
jTextField4.setText("" + people.get(count).getCountry());
jTextField6.setText("" + people.get(count).getTime());
count++;
}
public void dataMinus() {
jTextField1.setText("" + people.get(count).getRank());
jTextField2.setText("" + people.get(count).getFirstName());
jTextField3.setText("" + people.get(count).getLastName());
jTextField5.setText("" + people.get(count).getUciCode());
jTextField4.setText("" + people.get(count).getCountry());
jTextField6.setText("" + people.get(count).getTime());
count--;
}
private void search() {
String Name = jTextArea1.getText();
String record = "";
int count = 0;
for (int i = 0; i < people.size(); i++) {
String name = people.get(i).getFirstName();
String[] splitName = name.split(" ");
if (Name.equals(splitName[0]) || Name.equals(splitName[1])) {
count++;
record = record + "\n" + people.get(i).toString();
}
jTextArea1.setText("");
jTextArea1.append(count + " result(s) found for " + Name);
jTextArea1.append("\n " + record);
}
}