//
import java.awt.*;

// Example for class discussion
// unsupported code, usual disclaimers.
// Author: Jim McIntyre

public class Anim extends java.applet.Applet implements Runnable {
	String s;                                   // string to be displayed
    Rectangle r;                                // size of applett
    int x,y,xdir=1,ydir=1;						// location and direction
    Thread MyThread=null;                       // thread for bacground animation
	
    public void init() {                            // Initialize (b4 start)
		s = getParameter("Text");               // get s from browser
		
		String temp = getParameter("XDIR");     // get 'x' movement
		if(temp!=null) xdir = Integer.parseInt(temp);
		
		temp = getParameter("YDIR");            // get 'y' movement
		if(temp !=null) ydir = Integer.parseInt(temp);
		
		r = bounds();                           // Get our graphic size
		x = r.width/2;                          // Start at middle of screen
		y = r.height/2;
    }
	
    public void run() {                         // routine for bacground thread
        for(;;) {
			if(xdir+x > r.width || xdir+x < 0) { xdir = xdir * -1; }
			if(ydir+y > r.height || ydir+y < 0) { ydir = ydir * -1; }
			x+=xdir; y+=ydir;
			repaint();
			Rest(1);
        }
    }
	
    void Rest(int r) {                          // waste some time
        try{
			MyThread.sleep(5*r);
        }catch (InterruptedException e) {
			return;
        }
    }
	
    public void start() {                       // Browser signalling to start running
        if(MyThread == null) {
			MyThread = new Thread(this);
			MyThread.setPriority(Thread.NORM_PRIORITY -1);
			MyThread.start();
        }
    }
	
    public void stop() {                        // Browser signalling to stop
        if(MyThread != null) {
            MyThread.stop();
            MyThread=null;
        }
    }
	
    public void paint(Graphics g) {				// Browser wants us to paint
        g.setColor(Color.blue);
        if(s!=null) g.drawString(s,x,y);
        g.drawRoundRect(x-10,y-20,80,30,10,10);
    }
}






Make your own free website on Tripod.com