
/**
 *
 * demonstration of threads version III
 *
 * Written by: Roger Garside
 *
 * First Written: 6/Feb/97 
 * Last Rewritten: 6/Feb/97
 *
 */

class ProcessString2 implements Runnable
    {
    private String originalString ;

    public ProcessString2(String string)
	{
	originalString = string ;

	Thread thisThread = new Thread(this) ;
	thisThread.start() ;
	} // end of constructor method

    public void run()
	{
	int offset = 0 ;
	while (true)
	    {
	    String s = originalString.substring(0, offset) +
		Character.toUpperCase(originalString.charAt(offset))
		+ originalString.substring(offset + 1) ;
	    System.out.println("**" + s + "**") ;
	    offset++ ;
	    if (offset == originalString.length())
		offset = 0 ;
	    try {
		Thread.sleep(1000) ;
		}
	    catch (InterruptedException e)
		{
		}
	    }
	} // end of method run

    } // end of class ProcessString2

public class Chapter21n6
    {
    public static void main(String[] args)
	{
	ProcessString2 p1 = new ProcessString2("lancaster") ;
	ProcessString2 p2 = new ProcessString2("preston") ;
	ProcessString2 p3 = new ProcessString2("kendal") ;

	while (true)
	    {
	    System.out.println("Hello again") ;
	    try {
		Thread.sleep(5000) ;
		}
	    catch (InterruptedException e)
		{
		}
	    }
	} // end of method main
    } // end of class Chapter21n6


