import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class IndexDemoS extends JFrame {

    private JTextField str , substr;
    private JButton b1;
    private JLabel l1 , l2 , l3;

    public IndexDemoS()
    {
	super( "The indexOf demo 1.0" );
	
	Container c = getContentPane();
	c.setLayout( new FlowLayout() );

	l1 = new JLabel("Enter a string, the substring to search for, then bonk on the button");
	c.add(l1);
	
	l2 = new JLabel("String : ");
	c.add(l2);

	str = new JTextField(25);
	c.add(str);


	l3 = new JLabel("Substring : ");
	c.add(l3);

	substr = new JTextField(25);
	c.add(substr);

	b1 = new JButton("I'm done!");
	b1.addActionListener( new ActionListener() 
	    {
		public void actionPerformed ( ActionEvent e )
		{

		    String findIn = str.getText();
	
		    String find = substr.getText();

		    int found = findIn.indexOf(find);

       	   
	
		    if(found == -1)
			{
			    JOptionPane.showMessageDialog(new JFrame() , "Substring not found" , "The indexOf result" , JOptionPane.WARNING_MESSAGE);
 
			}
		    else
			{
			    JOptionPane.showMessageDialog(new JFrame() , "Index was : " + found , "The indexOf result" , JOptionPane.INFORMATION_MESSAGE);
			
			}
		  
		    
		}
	    }
			      );
	c.add(b1);
	
	setSize( 400 , 150 ); // h,v
	show();
    }
    //this part of the program
    public static void main( String args[] )
    { 
	IndexDemoS app = new IndexDemoS();

	app.addWindowListener(
			      new WindowAdapter() {
				      public void windowClosing( WindowEvent e )
				      {
					  System.exit( 0 );
				      } //windowClosing
				  } //WindowAdapter
			      ); // WindowListner
    } //main


}

