// Glow buttons - the name says it all // Amit C. (ConnectSoft Ruksun, Pune, India) amit@maverick.corus.co.in import java.awt.Color ; import java.awt.Graphics; import java.util.Date; import java.lang.String ; import java.util.StringTokenizer; public class glowbutton extends java.applet.Applet implements Runnable { Thread GlowThread ; int i = 0 ; Color GlowColor1 = new Color(0,0,0); Color GlowColor2= new Color(0,0,0); Color GlowColor3 = new Color(0,0,0); public void init() { // The glowing colors GlowColor1 = StringToColor ( MygetStringParam("glowcolor1", "0,0,0"), Color.cyan ) ; GlowColor2 = StringToColor ( MygetStringParam("glowcolor2", "0,0,0"), Color.darkGray ) ; GlowColor3 = StringToColor ( MygetStringParam("glowcolor3", "0,0,0"), Color.magenta ) ; } public void start() { if (GlowThread == null) { GlowThread = new Thread(this, "Glow"); GlowThread.start(); } } public void run() { while (GlowThread != null) { repaint(); try { GlowThread.sleep(200); // Sleep for 800 millisec } catch (InterruptedException e) { } } } public void paint(Graphics g) { g.setColor (Color.black ) ; g.drawRect (0, 0, size().width - 1, size().height - 1 ) ; g.setColor (Color.gray ) ; g.drawRect (1, 1, size().width - 2, size().height - 2 ) ; g.drawRect (2, 2, size().width - 3, size().height - 3 ) ; if ( i == 0 ) // What color to fill in with! g.setColor (GlowColor1 ) ; else if (i == 1 ) g.setColor (GlowColor2 ) ; else g.setColor (GlowColor3 ) ; g.fillRect (3, 3, size().width - 4, size().height - 4 ) ; i = i+ 1 ; i = i % 3 ; } public void stop() { GlowThread.stop(); GlowThread = null; } // A changed version of getparam public String MygetStringParam (String att, String def) { String ret; try { ret = getParameter(att); if (ret.length() < 1) return def; else return ret; } catch(Exception e) { return def; } } // Given a string parses it to get the colors public Color StringToColor (String strColor_p, Color clrDefault_p ) { if (strColor_p.length ( ) == 0) { return clrDefault_p ; } int r; int g; int b; // Delimiter is ',' StringTokenizer st = new StringTokenizer (strColor_p, ",") ; try { r = Integer.valueOf(st.nextToken()).intValue(); g = Integer.valueOf(st.nextToken()).intValue(); b = Integer.valueOf(st.nextToken()).intValue(); return new Color(r,g,b); } catch (Exception e) { return clrDefault_p; } } }