JAVA CODE

//Ex13_6 program
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class Ex13_6 extends Applet
             implements ActionListener
{
   private Label InputLbl, SearchLbl;
   private TextField InputTxt, SearchTxt, ResultTxt;
   private String s[];
   private final int ASIZE = 10;
   private int size;

   public void init()
   {
      s = new String[ASIZE];
      for (int i = 0; i < 10; i++) s[i] = new String();

      InputLbl = new Label ("Enter text");
      add (InputLbl);

      InputTxt = new TextField (30);
      InputTxt.addActionListener (this);
      add (InputTxt);

      SearchLbl = new Label ("Search word");
      add (SearchLbl);

      SearchTxt = new TextField (20);
      SearchTxt.addActionListener (this);
      add (SearchTxt);

      ResultTxt = new TextField (25);
      ResultTxt.setEditable (false);
      add (ResultTxt);
   }

   public void paint (Graphics g)
   {
      for (int i = 0; i < s.length; i++)
         g.drawString ((i+1) + ". " + s[i], 20, 100 + 20 * i);
   }

   public void actionPerformed (ActionEvent e)
   {
      if (e.getSource() == InputTxt)
      {
         ResultTxt.setText ("");
         if (size < ASIZE)
         {
            s[size] = InputTxt.getText();
            size++;
         }
      }
      else if (e.getSource() == SearchTxt)
      {
         findTxt (SearchTxt.getText());
      }

      InputTxt.setText("");
      SearchTxt.setText("");
      repaint();
   }

   private void findTxt (String search)
   {
      for (int i = 0; i < s.length; i++)
         if (s[i].indexOf (search) != -1)
         {
            ResultTxt.setText (search + " found in array.");
            return;
         }

      ResultTxt.setText (search + " not found in array.");
   }
}