import java.awt.*;
import java.awt.event.*;

public
class HelloApp extends Frame implements WindowListener, ActionListener
{
   Button button;
   TextField textField;
   TextArea textArea;
   public HelloApp ()
   {
      super();
      addWindowListener(this);
      setSize(320, 200);
      setTitle("Moja aplikacja w Javie");
      setLayout(null);

      button = new Button("Szukaj");
      this.add(button);
      button.addActionListener(this);
      button.setBounds(210, 140, 60, 20);
      
      textField = new TextField();
      textField.setBounds(10, 140, 160, 20);
      this.add(textField);
      
      textArea = new TextArea();
      textArea.setBounds(10, 30, 260, 100);
      this.add(textArea);

      setVisible(true);
      button.setVisible(true);
      textField.setVisible(true);
      textArea.setVisible(true);
   }
   public void paint(Graphics gDC)
   {
   }
   public static void main(String args[])
   {
      new HelloApp();
   }
   public void szukaj(){
      String tekst = textArea.getText();
      String ciag = textField.getText();
      int indeks = 0;
      int indeks_wystapienia = 0;
      int liczba_wystapien = 0;
      while (indeks_wystapienia != -1){
         indeks_wystapienia = tekst.indexOf (ciag, indeks);
         if (indeks_wystapienia != -1){
            indeks = indeks_wystapienia + 1;
            liczba_wystapien++;
         }
      }
      new MyDialog(this, "", String.valueOf(liczba_wystapien));
   }
   public void actionPerformed(ActionEvent e){
      if (e.getActionCommand() == "Szukaj"){
         szukaj();
      }
   }
   public void windowClosing(WindowEvent e){
      System.exit(0);
   }
   public void windowClosed(WindowEvent e){
   }
   public void windowOpened(WindowEvent e){
   }
   public void windowIconified(WindowEvent e){
   }
   public void windowDeiconified(WindowEvent e){
   }
   public void windowActivated(WindowEvent e){
   }
   public void windowDeactivated(WindowEvent e){
   }
}
