FileDocCategorySizeDatePackage
Scroller.javaAPI DocExample2711Mon Oct 16 19:44:02 BST 2000None

Scroller

public class Scroller extends Applet implements Runnable

Fields Summary
private volatile boolean
suspended
private TextArea
display
private String[]
text
private Thread
t
private int
delay
Constructors Summary
Methods Summary
public voiddestroy()

  Thread toGo = t;
      t = null;
      toGo.interrupt();
   
public voidinit()

  // get data from HTML
      String s = getParameter( "FontSize" );
      int points;
      if( s == null )
      {  points = 10;
      }
      else
      {  points = Integer.parseInt( s.trim() );
      }

      s = getParameter( "Delay" );
      if( s == null )
      {  delay = 50;
      }
      else
      {  delay = Integer.parseInt( s.trim() );
      }
      
      s = getParameter( "Lines" );
      int lines;
      if( s == null )
      {  lines = 0;
      }
      else
      {  lines = Integer.parseInt( s.trim() );
      }
      if( lines > 0 )
      {  text = new String[ lines ];
         int line;
         for( line = 0; line < lines; line += 1 )
         {  String name = "Line" + line;
            text[line] = getParameter( name );
         }
      }
      setLayout( new BorderLayout() );
      display.setFont( new Font( "Serif", Font.PLAIN, points ) );
      add( display ); // Center is default (1.1/1.0.2)
      
      // Thread bits
      t = new Thread( this );
      t.start();
      suspended = true;;
   
private voidoutputChar(char ch)

  display.insert( "" + ch, display.getText().length()-1 );
      t.sleep( delay );
   
public voidrun()

  Thread current = Thread.currentThread();
      while( t == current )
      {  try
         {  while( suspended )
            {  synchronized(this)
               {  wait();
               }
            }
            int line;
            for( line=0; line < text.length; line += 1 )
            {  for( int ch = 0; ch < text[line].length(); ch += 1 )
               {  outputChar( text[line].charAt( ch ) );
               }
               outputChar( '\n" );
            }
            for( line = 0; line < 10; line += 1 )
            {  outputChar( '\n" );
            }
            display.setText( "_" );
         }
         catch( InterruptedException ioe )
         {}
      }
   
public voidstart()

   
     
     synchronized(this)
      {  suspended = false;
         notify();
      }
   
public voidstop()

  suspended = true;