Can you help me with this code, I need to find a word, but it only finds first word, how to find multiple words?
lass managerClass implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e) {
String myWord = txt.getText();
Highlighter h = textArea.getHighlighter();
String searchArea = textArea.getText();
if (e.getSource() == bFind)
{
String[] searchArray = null;
searchArray = searchArea.split("[^A-Z][^a-z][^0-9]");
for(String element : searchArray)
{
if(element.equals(myWord))
{
pattern = Pattern.compile("\\b"+myWord+"\\b");
for (int i = 0; i < searchArray.length; i++)
{
Matcher matcher = pattern.matcher(searchArray[i]);
while( matcher.find() )
{
int start = matcher.start();
int end = matcher.end();
try {
//Highlighter hilit = new DefaultHighlighter();
Highlighter.HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW);
//h.addHighlight(start, end, DefaultHighlighter.DefaultPainter);
h.addHighlight(start, end, painter);
textArea.setSelectionStart(start);
textArea.setSelectionEnd(end);
textArea.setSelectedTextColor(Color.PINK);
}
catch (BadLocationException e1) {
e1.printStackTrace();
}
}
}
}
else
{
JOptionPane.showMessageDialog(null, "No match found", "Message", JOptionPane.INFORMATION_MESSAGE);
}
}
}
}