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 StringOutputter extends SimpleFrame 013 implements Animate, InputAcceptor, Initializable 014 { 015 private InputConnection in; 016 private TextField textField; 017 018 019 private static int instanceNumber; 020 private final int myIndex; 021 022 023 public StringOutputter () 024 { 025 super( new TextField( 40 ) ); // 40 = # columns 026 027 028 this.myIndex = instanceNumber++; 029 030 this.textField = (TextField) super.c; 031 this.textField.setEditable( false ); 032 033 MouseListener ml = TVConnectManager.getListener( this ); 034 this.textField.addMouseListener( ml ); 035 this.addMouseListener( ml ); 036 037 this.setTitle( this.toString() ); 038 039 Console.println( this + " created"); 040 041 new AnimatorThread( this ).startExecution(); 042 } 043 044 045 public String toString() 046 { 047 return this.getClass().getName() + " #"+this.myIndex; 048 } 049 050 public void addInputConnection( InputConnection in ) 051 throws ConnectionRejectedException 052 { 053 if ( this.in != null ) 054 { 055 throw new 056 ConnectionRejectedException ("Redundant input connection rejected" ); 057 } 058 else 059 { 060 this.in = in; 061 Console.println( "SO: Added input connection" ); 062 } 063 } 064 065 public void act () { 066 // Console.println ("Out: acting..."); 067 if ( this.in != null ) 068 { 069 // Console.println ("Out: got something!" ); 070 this.textField.setText( this.in.readInput() ); 071 } 072 } 073 } 074 075 076