Help with Search tools

I'm trying to create a search tool, that would search a users request in it's database and try and come up with an answer.. I've got the layout done and everything, I just keep getting incompatible errors, I know the program can accept the information because I tested it, it just can't seem to compare it against anything else.. This is what I have

JButton buttonPressed = (JButton)e.getSource();

if (buttonPressed == user)

{

Search = SearchField.getText();

if(Search == USER1)

{ JOptionPane.showMessageDialog(null,"User ID " + Search + " Found");

}

}

Search

User and Search are both JButtons, and USER1 is a String for "asdf" .. Please tell me what I'm doing wrong.

[741 byte] By [Pandemic] at [2007-11-26 7:42:54]
# 1

If Search and USER1 are of type JButton, you can not assign strings to them. I am not quite clear on exactly what part of the button you are trying to set. Are you just trying to set the button text?

This might help you.

String myString = "test";

JButton testButton1;

JButton testButton2;

testButton1.setText(myString); //Are you try to set the text or

testButton2.setText(myString);

if ( testButton2.getText().equals(testButton1.getText()))

System.out.println("I have a match.");

Looking more specifically at your code, try this.

JButton buttonPressed=(JButton)e.getSource();

if( buttonPressed.getText().equals(user))

{

Search.setText(SEarchField.getText());

if( Search.getText().equals(USER1.getText())

{

JOptionPane.showMessageDialog(null, "User ID" + Search + "Found");

}

}

I did not run this last code through and editor, so watch out for syntax errors.

Please let me know if you have any other questions.

Regards,

CreatorTeam

joelleLam at 2007-7-6 19:51:36 > top of Java-index,Development Tools,Java Tools...