This could do the trick
...
double room_width,room_height; // aplet dimensions
double radius=5;
double ballx=200,bally=200,xspeed=0,yspeed=0,bounces=0,crossx=500,crossy=100;
...
public boolean mouseDown (Event e, int x, int y){
if(xspeed==0 && yspeed==0){
double dist=Math.sqrt((ballx-x)*(ballx-x)+(bally-y)*(bally-y));
xspeed=5*(x-ballx)/dist;
yspeed=5*(y-bally)/dist;
}
}
public void run(){
while(true){
ballx+=xspeed;
bally+=yspeed;
if(ballx<radius || ballx>room_width-radius){
xspeed=-xspeed;bounces++;
}
if(bally<radius || bally>room_height-radius){
yspeed=-yspeed;bounces++;
}
if(bounces>2){
bounces=0;xspeed=0;yspeed=0;
ballx=room_width*Math.random();
bally=room_height*Math.random();
crossx=room_width*Math.random();
crossy=room_height*Math.random();
// pop up the message "missed"
}
if(ballx>crossx-10 && ballx<crossx+10 && bally>crossy-10 && bally<crossy+10 && bounces>0){
bounces=0;xspeed=0;yspeed=0;
ballx=room_width*Math.random();
bally=room_height*Math.random();
crossx=room_width*Math.random();
crossy=room_height*Math.random();
// pop up the message "got it!"
}
}
...
}
public void paint(Graphics g){
g.drawImage(ball,(int)ballx,(int)bally,null,this);
g.drawImage(cross,(int)crossx,(int)crossy,null,this);
...
}