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