Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

whats wrong with my code?

807598Apr 19 2006 — edited Apr 19 2006
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 17 2006
Added on Apr 19 2006
2 comments
82 views