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

[2128 byte] By [TheInsider] at [2007-9-30 21:09:21]
# 1

The following may work out. I assume u r having a find dialog box.

getRootPane().setDefaultButton(okButton);

okButton.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

findText();

okButton.setEnabled(false);

getRootPane().setDefaultButton(nextButton);

}

});

nextButton.addActionListener(new ActionListener())

{

public void actionPerformed(ActionEvent e)

{

findText();

}

}

private void findText()

{

findThisWord = findTF.getText();

myTextArea.setCaretPosition(0);

String fromWord=myTextArea.getText();

int caretPos=myTextArea.getCaretPosition();

int len=myTextArea.getText().length()-findThisWord.length();

for(int i = caretPos;i<len;i++)

{

String temp = fromWord.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;

}

}

}

Now, when u press ><Enter> key in textbox, the ok button will be activated first, after which it will be

disabled and the next button will be the default button

Aswin at 2007-7-7 2:42:31 > top of Java-index,Administration Tools,Sun Connection...