import java.awt.*; import java.applet.Applet; import java.awt.event.*; public class Koduliik extends Applet implements Runnable, KeyListener{ int y=150; int x=20; int m=1; int k=0; boolean veel=true; public Koduliik(){ addKeyListener(this); requestFocus(); new Thread(this).start(); } public void joonista(){ Graphics g=this.getGraphics(); if(g!=null){ if(x>270){ m=-m; k=-k; } if(x<0){ m=-m; k=-k; } x=x+m+k; g.setColor(Color.black); g.drawOval(x, y, 10, 10); try{Thread.sleep(50);}catch(Exception e){} g.setColor(Color.white); g.drawOval(x, y, 10, 10); } } public void run(){ while(veel){ joonista(); } } public void keyPressed(KeyEvent e){ int kood=e.getKeyCode(); if(kood==KeyEvent.VK_LEFT)m--; if(kood==KeyEvent.VK_RIGHT)m++; } public void keyReleased(KeyEvent e){} public void keyTyped(KeyEvent e){} public static void main(String[] argumendid){ Frame f=new Frame(); f.add(new Koduliik()); f.setSize(300, 300); f.setVisible(true); } }