import java.applet.Applet; import java.awt.event.*; import java.awt.*; public class Auto1 extends Applet implements KeyListener{ int x=100, y=100; public Auto1(){ addKeyListener(this); } public void paint(Graphics g){ g.drawLine(x, y, x, y+30); } public void keyPressed(KeyEvent e){ int kood=e.getKeyCode(); if(kood==KeyEvent.VK_LEFT)x--; if(kood==KeyEvent.VK_RIGHT)x++; if(kood==KeyEvent.VK_UP)y--; if(kood==KeyEvent.VK_DOWN)y++; 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 Auto1()); f.setSize(300, 300); f.setVisible(true); } }