Man, correct your indentation. Start it from the EDT. Don't extend JFrame, you're just using it, so there's no need to extend it.
BufferedReader bf = new BufferedReader(new FileReader("test.txt"));
BufferedWriter writer = new BufferedWriter(new FileWriter("test.txt"));
You're reading and writing to the same file. Write to a temp file, delete the original and rename the temp file to test.txt
while (( line = bf.readLine()) != null){
if(line.contains(word)){
JOptionPane.showMessageDialog(null,"Data deleted!");
writer.write(word);
}
so, if the word is found you write it to the file and display a message stating that it's deleted?!
If your line contains the search word, you should not write it to the file.