import java.awt.*; import java.awt.event.*; import java.applet.*; public class Autosoit2 extends Applet implements KeyListener{ double x=100, y=50, pikkus=30, a=Math.PI/6, da=0.1; public Autosoit2(){ addKeyListener(this); } public void paint(Graphics g){ double x2=x+Math.cos(a)*pikkus; double y2=y+Math.sin(a)*pikkus; 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){a=a-da;} if(kood==KeyEvent.VK_RIGHT){a=a+da;} repaint(); } public void keyReleased(KeyEvent e){} public void keyTyped(KeyEvent e){} public static void main(String[] arg){ Frame f=new Frame("Joonest auto"); f.add(new Autosoit2()); f.setSize(200, 200); f.setVisible(true); } }