import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class Joon extends Applet implements KeyListener{ int laius=300; int korgus=300; int pikkus = 20; int samm = 4; double x = laius/2; double y = korgus/2; double nurk=0; public Joon(){ addKeyListener(this); } public void paint(Graphics g){ double x2=x+pikkus*Math.cos(nurk); double y2=y+pikkus*Math.sin(nurk); g.setColor(Color.white); g.fillRect(0, 0, laius, korgus); g.setColor(Color.black); g.drawLine((int)x, (int)y, (int)x2, (int)y2); } public void update(Graphics g){ paint(g); } public void keyPressed(KeyEvent e){ int key=e.getKeyCode(); if (key == KeyEvent.VK_LEFT) nurk = nurk-0.1; if (key == KeyEvent.VK_RIGHT) nurk = nurk+0.1; if (key == KeyEvent.VK_UP ) { x = x+Math.cos(nurk)*samm; y = y+Math.sin(nurk)*samm; } if (key == 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 args[]){ Frame f=new Frame(); f.add(new Joon()); f.setSize(310, 330); f.setVisible(true); } }