Hey

I am trying to do a game in java applet. But i need som help.

I basicly wanna make a game there you should watch out for the ball/balls in a specefic area.

1. I want the boll move random in a specefic area.
2. I want another boll/image on the same screen, but i wanna move the second boll/image with my keyboard.
3. When everything abow works, i wanna make so "the second image/boll that you can move with the keyboard are gona watch out for the boll, "so he dosen,t touch the first boll that moves randomly.

Could any one help me plz?




Here is what i have come so far with:

import java.awt.Event;

import java.awt.Graphics;
import java.applet.*;
import java.awt.Color;
import java.util.*;


public class Uppgift_prog extends Applet {
int x=80;
int y=10;
int riktning=0;
boolean ner=true;
Random rnd = new Random();



public void init () {

}
public void paint (Graphics g){
g.drawRect(10, 10, 150, 150);
g.setColor(Color.RED);
g.fillOval(x,y, 10, 10);
for(int i=0;i<10000000;i++);
uppdatera();

}

public void uppdatera() {
System.out.println(riktning);
/*switch(riktning){
case 1:
if(x>10)
x=x-5;
break;
case 2:
if(x<150)
x=x+5;
break;
case 3:
if(y>5)
y=y-5;
break;
case 4:
if(y<150)
y=y+5;
break;



*/
if(ner){
if(y< 150)
y=y+5;
else if(y>=150){
y=y-5;
ner=false;
}

}
else{
if(y>0)
y=y-5;
else if(y<=0){
ner=true;
y=y+5;

}
}
if(ner){
if(x< 150)
x=x+5;
else if(x>=150){
x=x-5;
ner=false;


}
}
else{
if(x>0)
x=x-5;
else if(x<=0){
ner=true;
x=x+5;
}
}




for(int t=0;t<10000000;t++);
repaint ();


}
private int mathrandom() {
// TODO Auto-generated method stub
return 0;
}
public boolean keyDown(Event evt, int key){
switch(key){
case Event.LEFT:
riktning=1;
break;
case Event.RIGHT:
riktning=2;
break;
case Event.UP:
riktning=3;
break;
case Event.DOWN:
riktning=4;
break;


}
uppdatera();
return true;
}
}