import java.applet.Applet; import java.awt.event.*; import java.awt.*; public class Exam2 extends Applet implements KeyListener{ double x=200, y=200; double nurk=0, pikkus=40, samm =10; public Exam2(){ 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); } 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){ x=x-Math.cos(nurk)*samm; y=y-Math.sin(nurk)*samm; } repaint(); } public void keyReleased(KeyEvent e){} public void keyTyped(KeyEvent e){} public static void main(String argumendid[]){ Frame f=new Frame("Autosőit"); f.add(new Exam2()); f.setSize(400, 400); f.setVisible(true); } }