So far I have gotten this applet to a working stage; The only problem is that it only works if the mouse is moving; If the mouse is not moved, then the entire thing grinds to a halt. It starts working again if the mouse is moved.
The way that it works is the paint method is called by mouseMoved method. Each time the the mouse is moved, it goes threw the paint method, and the game continues. The problem arises from when the mouseMoved method isn't called, so the paint method does not get called, and the entire thing just pauses until the mouse is moved.
I have tried the following:
Having the paint method be recursive so it will call itself. The problem with this is that then the mouselistener does not work, because the program is to busy painting a bunch of stuff moving around.
I also tried using threads so that the mouselistener would interrupt the paint method. This did not work, although this could have been because I do not understand how threads worked. If anyone knows how to implement this, it seems like it would work.
Here is the snip-it of code of the problematic areas;
public void paint( Graphics gr) {
if( Earth != null){
displayWorld(Earth);
for(int a =0; a < 100; a++){
Earth.run();
Earth.Worlds.get(2).forceMove(x,y);
}
try
{
Thread.sleep(100);
}
catch (InterruptedException ie)
{}
}
}
public void mouseMoved( MouseEvent e ) {
x = e.getX();
y = e.getY();
Graphics gr = getGraphics();
paint(gr);
}