import java.applet.*; import java.awt.*; import java.awt.image.*; import java.lang.*; import java.net.*; import java.io.*; public class MailMe extends Applet implements Runnable{ Image mailMan; Image mailBox; Image dog; Image zzz; Image backGroundImage; int manIndex; int boxIndex; int dogIndex; int zIndex; int manX; int dogX; int[] walkRight={0,1,2,3,4,2}; int[] turnLeft={5,6,10}; int[] walkLeft={11,12,10,8,9,10}; int[] turnRight={10,6,2}; int[] dogRight={0,1,0,2}; int[] dogLeft={3,4,3,5}; int[] zX={-20,327,327,328,328}; int[] zY={-20,9,10,9,10}; int Height=90; int Width=600; String backGroundGif=null; String eMailAddr=null; Image offScrImage; Graphics offScrGC=null; Thread kicker=null; boolean imageLoadError=false; Color backGround; URL mailTo=null; AudioClip barkNoise; 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(); r=g=b=0; param=getParameter("BACKRED"); if (param!=null) r=Integer.valueOf(param).intValue(); param=getParameter("BACKGREEN"); if (param!=null) g=Integer.valueOf(param).intValue(); param=getParameter("BACKBLUE"); if (param!=null) b=Integer.valueOf(param).intValue(); param=getParameter("BACKGROUND"); if(param!=null) backGroundGif=param; param=getParameter("EMAIL"); if(param!=null) { eMailAddr=param; try { mailTo=new URL("mailto:"+param); } catch(MalformedURLException e){} } backGround=new Color(r,g,b); } public void paint(Graphics g) { if((offScrGC!=null)) { if(backGroundImage!=null) offScrGC.drawImage(backGroundImage,0,0,this); else offScrGC.fillRect(0,0,Width,Height); if(eMailAddr!=null) { offScrGC.drawString("EMail me: ",50,15); offScrGC.drawString(eMailAddr,100,15); } offScrGC.drawImage(mailMan,manX,10-manIndex*100,this); offScrGC.drawImage(mailBox,565,23-boxIndex*100,this); offScrGC.drawImage(dog,dogX,48-dogIndex*100,this); offScrGC.drawImage(zzz,zX[zIndex],zY[zIndex],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() { mailMan=getImage(getCodeBase(),"images/mailman.gif"); while(mailMan.getHeight(this)<0) { try { wait(); } catch(InterruptedException e){} } mailBox=getImage(getCodeBase(),"images/mailbox.gif"); while(mailBox.getHeight(this)<0) { try { wait(); } catch(InterruptedException e){} } dog=getImage(getCodeBase(),"images/dog.gif"); while(dog.getHeight(this)<0) { try { wait(); } catch(InterruptedException e){} } zzz=getImage(getCodeBase(),"images/zzz.gif"); while(zzz.getHeight(this)<0) { try { wait(); } catch(InterruptedException e){} } if(backGroundGif!=null) { backGroundImage=getImage(getCodeBase(),backGroundGif); while(backGroundImage.getHeight(this)<0) { try { wait(); } catch(InterruptedException e){} } } else backGroundImage=null; } public void run() { int i,j; Thread.currentThread().setPriority(Thread.MIN_PRIORITY); manX=295; dogX=-60; manIndex=0; boxIndex=0; dogIndex=0; zIndex=0; 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(); j=0; while(true) { while(manX<511) { for(i=0;i<6;i++) { manX+=5; manIndex=walkRight[i]; if(dogX>-60) { dogIndex=dogLeft[j]; if(++j==4) j=0; dogX-=5; } repaint(); try { kicker.sleep(100); } catch (InterruptedException e){} } } if(boxIndex==0) boxIndex=1; else boxIndex=0; for(i=0;i<3;i++) { manIndex=turnLeft[i]; if(dogX>-60) { dogIndex=dogLeft[j]; if(++j==4) j=0; dogX-=5; } repaint(); try { kicker.sleep(100); } catch (InterruptedException e){} } while(manX>302) { for(i=0;i<6;i++) { manX-=5; manIndex=walkLeft[i]; if(dogX>-60) { dogIndex=dogLeft[j]; if(++j==4) j=0; dogX-=5; } repaint(); try { kicker.sleep(100); } catch (InterruptedException e){} } } for(i=0;i<3;i++) { manIndex=turnRight[i]; repaint(); try { kicker.sleep(100); } catch (InterruptedException e){} } manIndex=7; while(dogX<235) { for(i=0;i<4;i++) { dogX+=5; dogIndex=dogRight[i]; if(++zIndex==5) zIndex=1; repaint(); try { kicker.sleep(100); } catch (InterruptedException e){} } } dogIndex=6; repaint(); try { kicker.sleep(100); } catch (InterruptedException e){} dogIndex=0; j=0; manIndex=2; zIndex=0; repaint(); try { kicker.sleep(100); } 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(mailTo!=null) { getAppletContext().showDocument(mailTo); return true; } return false; } }