import java.applet.Applet; import java.awt.event.*; import java.awt.*; public class Auto3 extends Applet implements KeyListener, Runnable{ double x=100, y=100; double nurk=0, pikkus=30, samm=5; boolean algus=true; public Auto3(){ addKeyListener(this); } public void paint(Graphics g){ double x2=x+pikkus*Math.cos(nurk); double y2=y+pikkus*Math.sin(nurk); g.drawLine((int)x, (int)y, (int)x2, (int)y2); g.drawOval((int)x-5, (int)y-5, 10, 10); } public void run(){ while(true){ x=x+Math.cos(nurk)*samm; y=y+Math.sin(nurk)*samm; repaint(); try{Thread.sleep(200);} catch(Exception ex){} } } public void keyPressed(KeyEvent e){ if(algus){ new Thread(this).start(); algus=false; } int kood=e.getKeyCode(); if(kood==KeyEvent.VK_LEFT)nurk=nurk-0.1; if(kood==KeyEvent.VK_RIGHT)nurk=nurk+0.1; if(kood==KeyEvent.VK_UP){ samm=samm+1; } if(kood==KeyEvent.VK_DOWN){ samm=samm-1; } } public void keyReleased(KeyEvent e){} public void keyTyped(KeyEvent e){} public static void main(String argumendid[]){ Frame f=new Frame("Klahvikuular"); f.add(new Auto3()); f.setSize(300, 300); f.setVisible(true); } }