001 package stringtransformers; 002 003 import cs101.lang.Animate; 004 import cs101.io.connection.*; 005 import cs101.io.Console; 006 //import cs101.util.AnimateObject; 007 import cs101.util.gamecontrol.Initializable; 008 import cs101.lang.AnimatorThread; 009 import java.awt.*; 010 import java.awt.event.*; 011 012 public class Accumulator extends SimpleFrame 013 implements Animate, 014 InputAcceptor, 015 Initializable 016 { 017 private InputConnection in; 018 private TextArea textArea; 019 020 private static int instanceNumber; 021 private final int myIndex; 022 023 024 public Accumulator () 025 { 026 super( new TextArea(10,40) ); // 10 = rows, 40 = columns 027 028 029 this.myIndex = instanceNumber++; 030 031 this.textArea = (TextArea) super.c; 032 this.textArea.setEditable( false ); 033 034 MouseListener ml = TVConnectManager.getListener( this ); 035 this.textArea.addMouseListener( ml ); 036 this.addMouseListener( ml ); 037 038 this.setTitle( this.toString() ); 039 040 Console.println( this + " created"); 041 042 new AnimatorThread( this ).startExecution(); 043 } 044 045 046 public String toString() 047 { 048 return this.getClass().getName() + " #"+this.myIndex; 049 } 050 051 public void addInputConnection( InputConnection in ) 052 throws ConnectionRejectedException 053 { 054 if ( this.in != null ) 055 { 056 throw new 057 ConnectionRejectedException ("Redundant input connection rejected" ); 058 } 059 else 060 { 061 this.in = in; 062 Console.println( "SO: Added input connection" ); 063 } 064 } 065 066 public void act () { 067 // Console.println ("Out: acting..."); 068 if ( this.in != null ) 069 { 070 // Console.println ("Out: got something!" ); 071 this.textArea.append( this.in.readInput() + "\n" ); 072 } 073 } 074 } 075 076 077