/*
 * PigLatin class for Translator applet
 * $Id: SimplerPigLatin.java,v 1.2 1996/06/19 23:09:21 las Exp $
 *
 * Developed for "Rethinking CS101", a project of Lynn Andrea Stein's AP Group.
 * For more information, see <a href="http://www.ai.mit.edu/projects/cs101">the
 * CS101 homepage</a> or email <las@ai.mit.edu>.
 *
 * Copyright (C) 1996 Massachusetts Institute of Technology.
 * Please do not redistribute without obtaining permission.
 */

import cs101.util.StringUtils;

/**
 * PigLatin is an auxilliary class for the Translator applet which
 * actually handles the String transformation into Pig Latin.  It is a
 * while (true) {echo();} loop which runs in its own thread.<p>
 *
 * Note that the modularization of this applet is not what one might
 * expect from standard Java.  For more details, see the
 *      <a href="http://www.ai.mit.edu/projects/cs101/">
 *                    Rethinking CS101
 * </a> project of Lynn Andrea Stein's AP Group at the MIT
 * Artificial Intelligence Laboratory.<p>
 *
 * @see      Translator
 * @see      cs101.util.StringUtils
 *
 * @author   Emil Sit, sit@mit.edu
 * @author   Lynn Andrea Stein, las@ai.mit.edu
 * @author   Adrian Banard, inki@mit.edu
 * @version  $Id: SimplerPigLatin.java,v 1.2 1996/06/19 23:09:21 las Exp $
 *
 * Copyright 1996 Massachusetts Institute of Technology
 *
 */
public class PigLatin extends Thread {
    private Translator GUI;

   /**
    * PigLatin( Translator )
    *
    * This constructor takes a Translator GUI applet and builds a
    * PigLatin object which uses that GUI for IO.  The constructor
    * (a) stores the GUI for future reference and 
    * (b) starts the PigLatin thread running.
    *
    * @param    gui       Translator applet for IO.
    */  
    public PigLatin ( Translator gui ) {
        this.GUI = gui;
        this.start();
    }

   /**
    * run()
    *
    * An infinite loop which <br>
    * (a) gets a new word from the GUI, <br>
    * (b) possibly constructs a new version of it, and <br>
    * (c) asks the GUI to print it out.<p>
    *
    * Invoked by the constructor method of the PigLatin object.<p> 
    */  
    public void run () {

        while (true) {

            String nextWord = this.GUI.getNextWord();

            this.GUI.printWord( nextWord.substring(1)
                                + nextWord.substring(0,1)
                                + "ay" );
        }
    }

}


/*
 * Comments:
 *     Some code ideas borrowed from Java language tutorial and other
 *      java references.
 *
 * History:
 *     $Log: SimplerPigLatin.java,v $
 *     Revision 1.2  1996/06/19 23:09:21  las
 *     Cleaned up documentation.
 *
 *     Revision 1.1  1996/06/19 21:46:19  las
 *     Initial revision
 *     6-19-96  Documentation, modularity improved by las@ai.mit.edu
 *     6-18-96  "Final" version created by las@ai.mit.edu 
 *                  from PigLatin.java by sit@mit.edu
 *                       Translator.java,v 1.1 1996/06/08 19:30:11 sit Exp 
 *                       PigLatin.java,v 1.2 1996/06/08 19:26:16 sit Exp 
 *                  and IgpayAtinlay.java by inki@mit.edu
 *
 */

