Reputation: 471
I currently have 3 classes, a main class containing a GUI, and the fnameTxtField
, a customer class containing the data, and a customerList
class which gathers the data from the customer class, and puts it into an array list.
Upvotes: 0
Views: 335
Reputation: 81154
Where you are using fnameTxtField.getText
, Java is expecting you to declare a method parameter (kind of like declaring a variable). A parameter is information that your method is told about for one particular execution, instead of having to find out on its own.
So you are right in thinking you want something like this:
public void searchCustomer(String familyName) {
for (int i = 0; i < customer.returnID(); i++) {
customer search = search.get(i);
if (search.returnFamilyName().equals(familyName)) {
System.out.println("Index: " + i);
//removed return i;
return;
}
}
}
Then at the point of invocation (method call) specify that you want to use the value in your text field:
//...
searchCustomer(fnameTxtField.getText());
Upvotes: 0
Reputation: 1933
Quick fix: Refactor your method to have the following signature public void searchCustomer(String text) { ... }
and call it with
searchCustome(fnameTxtField.getText())
.
Then you could use the variable "text" in your method, so the line
if (search.returnFamilyName().equals(fnameTxtField.getText))
changes to
if (search.returnFamilyName().equals(text))
(Or don't have any parameters at all and add the [probably] missing parentheses to fnameTxtField.getText
)
Upvotes: 1