I don't know what is wrong with my code here, the if conditions there never run true.
String words [] = new String[10];{ //Store the word string
words[1] = "apple";
words[2] = "ice cream";}
String searchData = "";
JTextField mySearchArea = new JTextField(7);
public void init()
{
setLayout(new FlowLayout(FlowLayout.RIGHT,10,10);
add(mySearchArea);
mySearchArea.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
mySearchArea.requestFocusInWindow();
searchData = mySearchArea.getText();
search();
}
private void search(){
for(int i = 1; i <= 2 ; i++ ){ //never run true
if(words[i] == searchData){
j=1;
System.out.println(words[i]);
break;
}
else
System.out.println("Error");
}
}