import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class Liigu3 extends Applet implements KeyListener, Runnable{ double nurk=0; double raadius=50; double samm=0.01; int ooteaeg=10; //ms boolean veel=true; public Liigu3(){ addKeyListener(this); new Thread(this).start(); } public void keyPressed(KeyEvent e){ int kood=e.getKeyCode(); if(kood==KeyEvent.VK_UP) samm = samm + 0.01; if(kood==KeyEvent.VK_DOWN)samm = samm - 0.01; } public void joonista(){ Graphics g=this.getGraphics(); if(g!=null){ g.setColor(Color.white); g.fillRect(0, 0, getSize().width, getSize().height); int keskx=getSize().width/2; int kesky=getSize().height/2; g.setColor(Color.black); g.drawOval( keskx+(int)(raadius*Math.cos(nurk))-5, kesky+(int)(raadius*Math.sin(nurk))-5, 10, 10 ); nurk=nurk+samm; if(nurk>2*Math.PI)nurk-=2*Math.PI; } } public void run(){ while(veel){ joonista(); try{ Thread.sleep(ooteaeg); } catch(Exception e){e.printStackTrace();} } } public void keyReleased(KeyEvent e){} public void keyTyped(KeyEvent e){} public static void main(String argumendid[]){ Frame f=new Frame(); f.add(new Liigu3()); f.setSize(200, 200); f.setVisible(true); } }