Hello,
I am working on a project and am in need of search function.
How my system works:
User enters details
Stored into a text file
writes a blank line at the end of the record
when reading in the file, a new blank line = new record
So for example, userID, forename, surname would look like this in the text file:
1
John
Jones
2
Gareth
Williams
I can read and write just fine, but I am trying to setup search capabilities for the userID's.
I was wondering what's the best way to approach this?
This is all I have so far, I think I am partially there but I believe my errors lie within the for statement:
public void searchInvoice() {
String idInputString = JOptionPane.showInputDialog(null, "Please enter the Order ID you're searching for:");
int idInput = Integer.parseInt(idInputString);
for (int i = 0; i <= orderID.length; i++) {
if(idInput == i) {
txtInvoiceOrderID.setText(orderID[i]);
txtInvoiceForename.setText(customerForename[i]);
txtInvoiceSurname.setText(customerSurname[i]);
} else {
JOptionPane.showMessageDialog(null, "Order ID Not Found", "Error!", JOptionPane.WARNING_MESSAGE);
}
}
}
Many thanks for your time.