// // rctext.java -- rolling color text demo by Y.Shinjo // Created on1997/06/18 17:45:00 // import java.awt.* ; public class rctext extends java.applet.Applet implements Runnable { volatile Thread thread ; int fontsize = 24 ; Font font ; Color color[] ; int sleep = 100 ; int step = 5 ; int x, y, n ; String message ; public void init() { font = new java.awt.Font("TimesRoman",Font.PLAIN, fontsize ); message = getParameter("message"); if( message == null ) message="null" ; x = 0 ; y = 0 ; n = 0 ; color = new Color[6] ; color[0] = Color.green ; color[1] = Color.yellow ; color[2] = Color.orange ; color[3] = Color.red ; color[4] = Color.magenta ; color[5] = Color.blue ; } public void paint(Graphics g) { x += step ; if( x > getSize().width ) { FontMetrics fm = g.getFontMetrics(); x = - fm.stringWidth( message ); } y += step ; if( y > getSize().height + fontsize ) { y = 0 ; n ++ ; if( n>= color.length ) n = 0 ; } g.setFont( font ); g.setColor( color[n] ); g.drawString( message, x, y ); } public void start() { thread = new Thread(this); thread.start(); } public void stop() { thread = null; } public void run() { Thread thisThread = Thread.currentThread(); while( thread == thisThread ) { try { thisThread.sleep( sleep ) ; } catch( InterruptedException e ) { stop(); } repaint(); } } }