Click on Window and then use U,D,R or L keys

import java.applet.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class MoveBall extends Applet implements KeyListener
 {
  private int keyCode;
     private int x = 400;
     private int y  = 300;
     
	 public void init()
	  {setSize(800,600);
	     addKeyListener(this);
        }
       
    public void keyPressed(KeyEvent e){
         keyCode = e.getKeyCode();
       if (keyCode == KeyEvent.VK_R  )
           {x= x + 1;}
           if (keyCode == KeyEvent.VK_L    )
           {x= x - 1;}
           if (keyCode == KeyEvent.VK_U   )
           {y= y - 1;}
           if (keyCode == KeyEvent.VK_D   )
           {y= y + 1;}
           repaint();
           e.consume();}
           
           public void keyTyped(KeyEvent e){}
            public void keyReleased(KeyEvent e){}
        
	 public void paint (Graphics g)
	   {
	    g.setColor(Color.red);
		 g.fillOval(x,y,10,10);
	   }
   }