C:\Documents and Settings\nikgyu\Mina dokument\NetBeansProjects\Java_sajt\src\Anim.java
import java.applet.Applet;
import java.awt.Graphics;

public class Anim extends Applet implements Runnable {

    double x = 20, y = 30, vx = 1, vy = 0.5;

    public void start() {
        Thread t = new Thread(this);
        t.start();
    }

    public void run() {

        while (true) {
            x += vx;
            y += vy;
            if (x < 0 || getWidth() < x) {
                vx = -vx;
            }
            if (y < 0 || getHeight() < y) {
                vy = -vy;
            }
            repaint();
            try { Thread.sleep(10); } catch (Exception e) { }
        }
    }

    public void paint(Graphics g) {
        double vinkel = Math.atan2(vy, vx);
        double x2 = x + 10 * Math.cos(vinkel);
        double y2 = y + 10 * Math.sin(vinkel);
        g.drawLine( (int)x,(int)y,(int)x2,(int)y2);
    }
}