my simple program searchs words in a text file and compairs each word with the word inserted in theTextfield but somehow it isnt .
this is a sample of my code which does the compairing words.
private int noOfwordOne;
private int noOfwordTwo;
private int noOfwordThree;
private void Search(){
String line= null;
String splittingSpace = ("\\s");
String [] text = null;
try{
wordOne = textField1.getText();
wordTwo = textField2.getText();
wordThree = textField3.getText();
textArea.write(new FileWriter("text.txt"));
FileReader fr = new FileReader("text.txt");
BufferedReader br = new BufferedReader(fr);
while(br.readLine() !=null){
line = br.readLine();
text = line.split(splittingSpace);
for (int i = 0 ; i < text.length ; i++) {
if(wordOne == text.toString()){
this.noOfwordOne + =1;
}
if (wordTwo == text[i].toString()){
this.noOfwordTwo +=1;
}
if (wordThree ==text[i].toString()){
this.noOfwordThree +=1;
}
}
}
Labelw1.setText(noOfwordOne + " matches for " + wordOne);
System.out.println(noOfwordOne);
} catch (Exception e) {
System.out.println("File Not Found");
e.printStackTrace();
}
}
Im oviously inserting words in the text field that exist in the text.txt but the value of noOfwordOne is remaing 0
Can anyone point out what im doing wrong?
Thanks
Matt