/* Use this program to test your recursive functions. Method main creates a
   GUI with 7 int fields, 7 double fields, and 7 String fields.      
   Whenever the button in the GUI is pressed, method buttonPressed is called.
   Place code in this method to read fields, calculate, and store values
   back in fields.
   */
   
   import java.awt.*;

public class RecursionTest extends JLiveWindow {
  
   // Place code in the body of this method to process fields and store 
   // results in fields. Use
        
   //   getIntField(i)     for the number in int    field i; 0 is first field
   //   getdoubleField(i)  for the number in double field i; 0 is first field
   //   getStringField(i)  for the number in String field i; 0 is first field
   //   setIntField(i,v);      to store int value v in field i
   //   setDoubleField(i,v);   to store double value v in field i
   //   setStringField(i,v);   to store String value v in field i

   // Process click of button titled "Ready!"
   // This version reads the first String field, calls duplicate with it
   // as an argument, and displays the result in the second String field
   public Object buttonPressed() {
      String s= getStringField(0);
      String t= duplicate(s);
      setStringField(1, t);
      return null;
   }
   
   // = s but with every character duplicated 
   public static String duplicate(String s) { 
       if (s.length() == 0) 
            { return s;  } 
       // { s has at least one character } 
            String temp= duplicate(s.substring(1)); 
            return s.substring(0,1) + s.substring(0,1) + temp; 
   } 
   
     
   // Create an instance of me and show it
   public static void main(String args[]) {
      // The first argument to MyJLiveWindow is the number of int fields,
      // the second argument is the number of double fields, and
      // the third argument is the number of text (or String) fields.
      RecursionTest window= new RecursionTest(7, 7, 7);
      window.showWindow();
   }
   
   
   // Create my window with
   //    max( min(i,MAX_FIELDS), 0) integer fields,
   //    max( min(d,MAX_FIELDS), 0) double fields, and
   //    max( min(s,MAX_FIELDS), 0) String fields
   //    and a "ready" button
   public RecursionTest(int i, int d, int s) {
	 super(i, d, s);
   }
}
 
