Thread Exception - StackOverFlow

This code creates a "missile" by mouse clicks:

publicboolean mouseDown(Event e,int x,int y)

{

missiles[mc].reset(x,y);

enemyMissiles[emc].reset();

if (mc < missiles.length-1)

mc++;

else

mc = 0;

if (emc < enemyMissiles.length-1)

emc++;

else

emc = 0;

repaint();

returntrue;

}

Missile Class:

This is where I think the problem must be because after a certain amount of clicks the threads stop and I get a stack overflow, the run() method is screwy i guess:

package mainPackage;

publicclass Missileextends Threadimplements Runnable{

privateint destX, destY, size, alpha;

public Missile()

{

start();

}

publicvoid reset(int x,int y)

{

destX = x;

destY = y;

size=1;

alpha = 255;

}

publicint getDestX()

{

return destX;

}

publicint getDestY()

{

return destY;

}

// used for centering ovals

publicint getCenterX()

{

return destX-size/2;

}

// used for centering ovals

publicint getCenterY()

{

return destY-size/2;

}

publicint getSize()

{

return size;

}

publicint getAlpha()

{

return alpha;

}

publicvoid run()

{

if (size < 150)

size++;

if (alpha > 0)

alpha--;

try{sleep(5);}

catch (Exception e)

{e.printStackTrace();}

run();

}

}

If someone can please spot any errors, I would greatly appreciate it.

[3899 byte] By [yahwehagapea] at [2007-11-26 21:06:59]
# 1

Your run method is calling itself in an infinite recursion, resulting in a stack overflow.

public void run()

{

do some stuff that's not relevant to the problem;

run();

}

ChuckBinga at 2007-7-10 2:41:26 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2

So, what how would I code this differently. Maybe I should use a single thread in my client program instead of making an instance of a thread for every missile. And then I could just have a time variable for every missile and update this time as I go through my game loop. I use a recursive call to repaint(); is this okay? I recursively call repaint() in order to keep updating the graphics.

also, would have a time variable for each object be bad, i.e. would it run at different speeds on different processors? Would it be better to get the computers current time and work with that?

Thank you for helping.

yahwehagapea at 2007-7-10 2:41:26 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...