Hi my code is showing incompatible types with my JTextField. Is this not the correct way to do it?

Code java:

if(SearchField.equals("Stapler"))

This is for my button. SearchField = JTextField. The equals in the () is showing up as an incompatible type.

What should i do to correct it.

February 12th, 2013, 07:03 AM

aesguitar

Re: Incompatible types.

Strings are not JTextFields, you need to get what's in the text field to compare with a String.

February 12th, 2013, 03:10 PM

miller4103

Re: Incompatible types.

How would i do that? I need to be able to type in a string in the SearchField and when it equals lets say Stapler i need it to show some information. how do i get whats in the JTextField to compare with a string?

February 12th, 2013, 03:12 PM

Norm

Re: Incompatible types.

Quote:

how do i get whats in the JTextField to compare with a string?

Read the API doc for the JTextField class and find the method that will get the String that is int the text field.Java Platform SE 7

February 12th, 2013, 03:46 PM

miller4103

Re: Incompatible types.

Thanks norm i know its in there somewear and i looked but i cannot find it. Can you narrow it down some?

February 12th, 2013, 04:13 PM

Norm

Re: Incompatible types.

This one is a little more difficult than usual. The JTextField class extends a class that has the method you are looking for. And that class extends another class which has more methods etc.