FINDworksFINDNEXTdoesnt
FIND works FIND NEXT doesnt
hi there, i wrote this code but it didnt work. i feel it includes a bug or something
the Find was working untill i added the FindNext button, after this the both didnt work properly, thery just get the first word then STOP, why ? this is my question !!
so what is it guys ?
//the code
nextButton.setEnabled(false);
okButton.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
findThisWord = findTF.getText();
myTextArea.setCaretPosition(0);
int caretPos=myTextArea.getCaretPosition();
for(int i = caretPos;
i<(myTextArea.getText().length()-findThisWord.length());
i++)
{
String temp = myTextArea.getText().substring(i,i+findThisWord.length());
if(temp.equals(findThisWord))
{
myTextArea.select(i,i+findThisWord.length());
nextButton.setEnabled(true);
okButton.setEnabled(false);
break;
}
else
{
findDialog.dispose();
Toolkit.getDefaultToolkit().beep();
JOptionPane.showMessageDialog(null,
"The specified text was not found", "Find",JOptionPane.INFORMATION_MESSAGE);
break;
}
}
}
}
);
nextButton.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
findThisWord = findTF.getText();
int caretPos=myTextArea.getCaretPosition();
for(int i=caretPos;
i<(myTextArea.getText().length()-findThisWord.length());i++)
{
String temp=myTextArea.getText().substring
(i,i+findThisWord.length());
if(temp.equals(findThisWord))
{
myTextArea.select(i,i+findThisWord.length());
break;
}
else
{
findDialog.dispose();
Toolkit.getDefaultToolkit().beep();JOptionPane.showMessageDialog(null,
"Can not find this word any more",
"FindNext",
JOptionPane.INFORMATION_MESSAGE);
break;
}
}
}
}
);
//thanks in advance

