/* Theresa L. Walunas SE450 Section 303, Tuesday 5:45 - 9:00 pm Assignment #2, Due Date: 4/11/00 Modification of the Blink.java applet */ import java.awt.*; import java.util.StringTokenizer; public class Blink1 extends java.applet.Applet implements Runnable { Thread blinkThread; String blinkingtext; Font font; int speed; public void init() { font = new Font("Sans", Font.BOLD, 24); setBackground(new Color(255,255,204)); speed = 400; blinkingtext = "< > ! * ' ' # ^ @ ` $ $ - * ! ' $ _ % * < > #4 & ) .. / { ~ | * * SYSTEM-HALTED"; } public void paint(Graphics g) { int x = 0, y = font.getSize(), space; int red = 0; int green = 100; int blue = (int)(Math.random() * 256); Dimension d = getSize(); g.setColor(Color.black); g.setFont(font); FontMetrics fm = g.getFontMetrics(); space = fm.stringWidth(" "); for (StringTokenizer t = new StringTokenizer(blinkingtext); t.hasMoreTokens() ; ) { String word = t.nextToken(); int w = fm.stringWidth(word) + space; if (x + w > d.width) { x = 0; y = font.getSize(); } g.setColor(new Color(red, green % 256, blue % 256)); blue+=7; g.drawString(word, x, y); try { Thread.currentThread().sleep(350); } catch (InterruptedException e){} g.setColor(getBackground()); g.drawString(word, x, y); x += w; } } public void start() { blinkThread = new Thread(this); blinkThread.start(); } public void stop() { blinkThread = null; } public void run() { while (Thread.currentThread() == blinkThread) { repaint(); try { Thread.currentThread().sleep(speed); } catch (InterruptedException e){} } } }