I need to use Scanner and StringTokenizer to find a word then print that line in text area when found it.
This is the Search Button's coding :
private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {
try {
Scanner scan = new Scanner(file);
String search = txtSearch.getText();
while (scan.hasNextLine()) {
line = scan.nextLine();
StringTokenizer st = new StringTokenizer(line, ":");
while (st.hasMoreTokens()) {
word = st.nextToken();
if (word == search) {
txtOutput.setText("DVD List\n" + line);
} else {
txtOutput.setText("DVD Not Found");
}
}
}
scan.close();
SearchWin.dispose();
} catch (IOException iox) {
}
}
inside the text file is something like this:
Bleach:Anime:1999:G
Avatar:Sci-Fi:2009:PG-13
Toy Story:Animation:1995:G
The Proposal:Comedy:2009:PG-13
In this text file, i am using the ":" as my seperator.
but when I input a title at the textfield then press the search button, it will only show DVD Not Found. Can someone tell me where is the problem here?