Member Avatar for mehnihma

I have problem with selecting text, In this code it only selects one and finds one, hot to make it to find more?

public void actionPerformed(ActionEvent e)
      {
         if(e.getActionCommand().equals("ResetAll"))
         {
            area.setText("");
            search.setText("");
            found.setText("0");
         }
         else if(e.getActionCommand().equals("Exit"))
         {
            JOptionPane.showMessageDialog(frame, "Good-Bye","218 HW #5", JOptionPane.INFORMATION_MESSAGE);
            System.exit(0);
         }
         else if(e.getActionCommand().equals("Clear"))
         {
            area.setText("");
         }
         else if(e.getActionCommand().equals("Reset"))
         {
            found.setText("0");
           
         }
         else if(e.getActionCommand().equals("Search"))
         {
            String TextAreaBox = area.getText();
            String wordbox = search.getText();
         	
            if(TextAreaBox.equals(""))
            {
               JOptionPane.showMessageDialog(frame, "Target TextArea is empty");
            }
            else if(wordbox.equals(""))
            {
               JOptionPane.showMessageDialog(frame,"Search TextField is empty");
            }
            else
            {
               int index = TextAreaBox.indexOf(wordbox, 0);
               int counter = 0;
               
               if ((index > -1) && (index < TextAreaBox.length()))
               {
                  TextAreaBox = TextAreaBox.substring((index + wordbox.length()), TextAreaBox.length());
                  area.select(index, (index + wordbox.length()));
                  index = TextAreaBox.indexOf(wordbox, 0);
                  counter++;
               }
            	
               found.setText(counter + " ");
            }
         }
Member Avatar for mehnihma

I have solved this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.