import java.applet.*; import java.awt.*; import java.awt.image.*; import java.lang.*; import java.net.*; import java.io.*; public class LivingLink extends Applet implements Runnable{ Image gif=null; int gifIndex; int gifX=0; int Height=100; int Width=100; int pauseLen=150; int gifWidth; String gifStrip=null; Image offScrImage; Graphics offScrGC=null; Thread kicker=null; boolean imageLoadError=false; boolean urlError=false; boolean debug=false; URL link=null; Color backGround; public void init() { String param; int r,g,b; param=getParameter("height"); if (param != null) Height=Integer.valueOf(param).intValue(); param=getParameter("width"); if (param!=null) Width=Integer.valueOf(param).intValue(); param=getParameter("DEBUG"); if(param!=null) debug=true; param=getParameter("LINK"); if(param!=null) { try { link=new URL(param); } catch(MalformedURLException e){urlError=true;} } if(debug) { if(urlError) System.out.println("URL Error"); else System.out.println("No URL Error"); } param=getParameter("GIFSTRIP"); if(param!=null) gifStrip=param; if(debug) { if(gifStrip==null) System.out.println("No Gif Strip"); else System.out.println("Gif Strip = " + gifStrip); } param=getParameter("PAUSE"); if (param!=null) pauseLen=Integer.valueOf(param).intValue(); r=g=b=255; param=getParameter("BGCOLOR"); if(param!=null) { if(param.charAt(0)=='#') { r=readColorValue(param,1,3); g=readColorValue(param,3,5); b=readColorValue(param,5,7); } } if(debug) System.out.println("Colors, r="+r+" g="+g+" b="+b); backGround=new Color(r,g,b); } public int readColorValue(String param,int start,int stop) { String temp; try { temp=param.substring(start,stop); } catch(StringIndexOutOfBoundsException e){return 0;} try { return Integer.valueOf(temp,16).intValue(); } catch(NumberFormatException e){return 0;} } public void paint(Graphics g) { if(urlError) g.drawString("Malformed URL",10,Height/2-10); else if(imageLoadError) g.drawString("Images load error",10,Height/2-10); else if((offScrGC!=null)) { offScrGC.fillRect(0,0,Width,Height); offScrGC.drawImage(gif,-1*gifX,0,this); g.drawImage(offScrImage,0,0,this); } } public void update(Graphics g){ paint(g); } public synchronized boolean imageUpdate(Image img, int infoFlags, int x, int y, int width, int height) { if ((infoFlags & ERROR) != 0) { imageLoadError = true; } notifyAll(); return true; } public synchronized void loadImages() { gif=getImage(getCodeBase(),gifStrip); if (gif==null) imageLoadError=true; else while((gifWidth=gif.getWidth(this))<0) { try { wait(); } catch(InterruptedException e){} } if(debug) System.out.println("Gif Strip Loaded"); } public void run() { int i,j; Thread.currentThread().setPriority(Thread.MIN_PRIORITY); loadImages(); offScrImage=createImage(Width,Height); offScrGC=offScrImage.getGraphics(); offScrGC.setColor(backGround); repaint(); for(i=0;i<40;i++) { try { kicker.sleep(50); } catch (InterruptedException e){} } repaint(); while(true) { gifX+=Width; if (gifX>(gifWidth-Width)) gifX=0; if(debug) System.out.println("gifX ="+gifX); repaint(); try { kicker.sleep(pauseLen); } catch (InterruptedException e){} } } public void start() { if (kicker == null) { kicker = new Thread(this); kicker.start(); } } public void stop() { kicker.stop(); kicker = null; } public boolean mouseDown(Event evt,int x, int y) { if(debug) System.out.println("Mouse Click"); if(link!=null) { if(debug) System.out.println("Launching URL"); getAppletContext().showDocument(link); return true; } if(debug) System.out.println("No URL to launch"); return false; } }