import java.applet.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.AffineTransform;
import java.net.URL;

public class auto1 extends Applet implements ActionListener, Runnable
{
	int x_pos = 600;		
	int y_pos = 100;
	int nurk=0;
	int radius = 20;
	int kiirus=1;
	int kiirusauto=3;
	URL base; 
    Image kere,ratas;
    TextField tf1=new TextField();
    TextField tf2=new TextField();
    Image reket1=Toolkit.getDefaultToolkit().getImage("reket1.gif");
    Image reket2=Toolkit.getDefaultToolkit().getImage("reket2.gif");
    
    public auto1(){
        add(tf1);
        add(tf2);
        tf1.addActionListener(this); 
        tf2.addActionListener(this); 
    }

	public void init()
	{
		base = getDocumentBase(); 
        kere = getImage(base, "kere.gif");
        ratas = getImage(base, "ratas.gif");
		setBackground (Color.blue);
	}
	public void start ()
	{
		Thread th = new Thread (this);
		th.start ();
	}
	public void stop()
	{
	}
	public void destroy()
	{
	}
	public void run ()
	{
		while (true)
		{

			x_pos=x_pos-kiirusauto;
			nurk=nurk-kiirus;
			if(nurk>2*Math.PI)nurk-=2*Math.PI;
			repaint();
			try
			{
				Thread.sleep (20);
			}
			catch (InterruptedException ex)
			{
			}
		}
	}
	 public void actionPerformed(ActionEvent e){
	     kiirus=Integer.parseInt(tf1.getText());
	     kiirusauto=Integer.parseInt(tf2.getText());
	     repaint();
	 } 
	public void update(Graphics g){
	   paint(g);
	}
	public void paint (Graphics g)
	{
        Image puhver=createImage(getWidth(), getHeight());	    
	    Graphics2D g2 = (Graphics2D)puhver.getGraphics();
	    g2.drawImage(kere,x_pos - radius,y_pos - radius,this);
	    //g.drawImage(ratas,x_pos - radius+50+ringx,y_pos - radius+80+ringy,this);
	    //g.drawImage(ratas,x_pos - radius+210+ringx,y_pos - radius+80+ringy,this);
	    //Graphics2D g2 = (Graphics2D) g;
	    AffineTransform tx = new AffineTransform();
	    AffineTransform tx1 = new AffineTransform();
	    tx.translate(x_pos - radius+210,y_pos - radius+90);
	    tx1.translate(x_pos - radius+50,y_pos - radius+90);
	    //tx.rotate(Math.toRadians(nurk), ratas.getWidth(null), ratas.getHeight(null));
	    tx1.rotate(Math.toRadians(nurk), ratas.getWidth(null)/2, ratas.getHeight(null)/2);
	    tx.rotate(Math.toRadians(nurk), ratas.getWidth(null)/2, ratas.getHeight(null)/2);
	    g2.drawImage (ratas, tx, null);
	    g2.drawImage (ratas, tx1, null);
		//g.drawImage(kere,500,20,this);
		//g.drawImage(ratas,550,100,this);
		//g.drawImage(ratas,710,100,this);
        g.drawImage(puhver, 0, 0, this);
	}
public static void main(String argumendid[]){
    Frame f=new Frame("Linnud");
    f.add(new auto());
    f.setSize(500, 400);
    f.setVisible(true);
    }
}

