Passing JTextField as String parameter
Hello,
I made a GUI for a simple class that stores accountnumbers and customernames in an arraylist.
In the class I made a public String getAccountNumber(customername), this returns the accountnumber that is linked to a customer with "customername".
In the GUI I made a JTextField where one can provide a customername and a button that triggers the getAccountNumber with parameter: JTextField.getText().
However, it doesn't work with parameter: JTextField.getText(). When I type the name of the customer myself (hardcoded) it does work (???).
Is there something else I have to convert/... to pass the JTextField.getText() to my getter so it returns the result correctly?
Best regards,
Christophe
Re: Passing JTextField as String parameter
What is the error you get?
I'm not sure but try: JTextField.getText().toString()
1 Attachment(s)
Re: Passing JTextField as String parameter
Hi,
The ...toString() doesn't work either.
I am not getting a specific error, it just doesn't find any results and returns the String 'no result found' (which I programmed to do if no matches are found).
I put my code in attachment, feel free to try, maybe one of you guys knows what the problem is. I am quite new at Java (and programming in general).
Best regards,
Christophe
Re: Passing JTextField as String parameter
Hello,
I found the solution for this problem.
In my procedure I used this code:
if('string1' == 'string2') {...} => this is wrong since I want to compare the content of the strings, I had to use:
if('string1.equals(string2)) {...} => this is correct, this compares the content of both strings.
That's it.
Best regards,
Christophe