import java.applet.Applet; import java.awt.event.*; import java.awt.*; public class Auto2 extends Applet implements KeyListener{ double x=100, y=100; double nurk=0, pikkus=30, samm=5; public Auto2(){ 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 keyPressed(KeyEvent e){ 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){ x=x+Math.cos(nurk)*samm; y=y+Math.sin(nurk)*samm; } if(kood==KeyEvent.VK_DOWN); repaint(); } public void keyReleased(KeyEvent e){} public void keyTyped(KeyEvent e){} public static void main(String argumendid[]){ Frame f=new Frame("Klahvikuular"); f.add(new Auto2()); f.setSize(300, 300); f.setVisible(true); } }