import java.applet.*; import java.awt.*; abstract class Animation { protected Applet app; protected void init(Applet app) { this.app = app; } public abstract void advance(); public abstract void paintFrame(Graphics g); } class StarAnimation extends Animation { private Color color = new Color(0,0,0); private static int i = 0, r = 0, g = 0, b = 0; public void advance() { switch (i++) { case 5: color = Color.darkGray; break; case 6: color = Color.lightGray; break; case 7: color = Color.white; break; case 8: color = Color.lightGray; break; case 9: color = Color.darkGray; break; case 50: color = Color.black; i = 0; break; default: color = Color.black; break; } } public void paintFrame(Graphics g) { Rectangle bounds = app.bounds(); g.setColor(Color.black); g.fillRect(0,0,bounds.width,bounds.height); g.setColor(color); g.fillOval(0,0,bounds.width,bounds.height); } } public class Pulsar extends Applet implements Runnable { Thread animator; Animation animation; private int timing; private StringBuffer timingStringBuf; public void init() { animator = new Thread(this); animation = new StarAnimation(); animation.init(this); timingStringBuf = getParameter("timing"); timing = (int) timingStringBuf.toString() } public void start() { if (animator.isAlive()) { animator.resume(); } else { animator.start(); } } public void stop() { animator.suspend(); } public void destroy() { animator.stop(); } public void run() { try { while (true) { repaint(); Thread.sleep(100); animation.advance(); } } catch (Exception e) { e.printStackTrace(); return; } } public void paint(Graphics g) { animation.paintFrame(g); } }