// // Animation test // //import java.awt.Graphics; //import java.awt.Image; import java.awt.*; import java.lang.Math; public class Animation extends java.applet.Applet implements Runnable { Image Pic ; boolean loop = true; Thread kicker = null; int px=0 ; int py=0 ; int width =80 ; int height =60 ; int wait =50 ; int imgwidth = 0 ; int imgheight= 0 ; String fname ="" ; public void init() { width =Integer.parseInt(getParameter("width")) ; height=Integer.parseInt(getParameter("height")) ; wait =Integer.parseInt(getParameter("wait")) ; String fname = getParameter("fname") ; Pic=getImage(getCodeBase(), fname); MediaTracker mt = new MediaTracker(this) ; mt.addImage(Pic,0) ; try{ mt.waitForAll() ; }catch (InterruptedException e){return;} imgwidth =Pic.getWidth(this) ; imgheight=Pic.getHeight(this) ; } public void paint(Graphics g) { update(g); } public void update(Graphics g) { if(Pic==null) { g.drawString("Error when loading picture", 0, 0); } g.drawImage(Pic,px,py, this); } public void start() { if(kicker == null) { kicker=new Thread(this); kicker.start(); } } public void stop() { if ( kicker != null ) { kicker.stop(); kicker = null; } } public void run() { while(loop) { repaint(); px-=width ; if( px<=-(imgwidth) ){ px=0 ; py-=height ; if( py<=-(imgheight) ){ py=0 ; } } try { Thread.sleep( wait ); } catch (InterruptedException e){} } } }