import java.awt.*; import java.applet.Applet; import java.awt.event.*; import javax.swing.*; public class mobile extends Applet implements Runnable,KeyListener { double nurk=0; double raadius=50; double samm=0.02; int ooteaeg=20; //ms boolean veel=true; public mobile() { new Thread(this).start(); addKeyListener(this); } 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 keyPressed(KeyEvent syndmus) { int nupp = syndmus.getKeyCode(); if (nupp == KeyEvent.VK_RIGHT) { ooteaeg+=1; } if (nupp == KeyEvent.VK_LEFT) { if (ooteaeg>5) { ooteaeg-=1; } } } public void keyReleased(KeyEvent syndmus) { } public void keyTyped(KeyEvent evt) { } public static void main(String argumendid[]) { Frame f=new Frame(); f.add(new mobile()); f.setSize(200, 200); f.setVisible(true); } }