// Lars Sorensen TYJava in 21 days // excode from pg 184, the swirling colors // // // import java.awt.Graphics; import java.awt.Font; import java.awt.Color; public class ColorSwirl extends java.applet.Applet implements Runnable { Font theFont = new Font("TimesRoman", Font.BOLD, 48); Color colors[] = new Color[50]; Thread runner; public void start() { if (runner == null ) { runner = new Thread(this); runner.start(); } } // end of start public void stop() { if (runner != null ) { runner.stop(); runner = null; } } // end of stop public void run() { // init the color array float c = 0; for (int i = 0; i < colors.length; i++ ) { colors[i] = Color.getHSBColor(c, (float)1.0,(float)1.0); c += .02; } // cycle through the colors.... int i = 0; while (true) { setForeground(colors[i]); repaint(); i++; try { Thread.sleep(50); } catch (InterruptedException e) { } if ( i == colors.length ) i = 0; } } // end of run public void paint(Graphics g) { g.setFont(theFont); g.drawString(" M E T A L L I C A ", 15, 50); } // end of paint // Overiding the update method to get rid of flicker public void update(Graphics g) { paint(g); } // end of overriden update } // end of ColorSwirl.