public class Simulation implements Runnable{ private New_Box app; private double var[],new_var[]; private int M=4; private double XMIN=-1.0,XMAX=1.0,YMIN=-1.0,YMAX=1.0; // Constructor method saves name of applet Simulation(New_Box box){ app=box; var = new double[M]; new_var = new double[M]; } // Simulation must supply a run method if it implements the Runnable Interface public void run(){ // setup infinite loop while(true){ // update position of ball update(); // wait 5 millisecs between calls to paint try{Thread.sleep(10);} catch(InterruptedException e){} app.repaint(); } } private void update(){ double t,dt; // allow balls to interact via a repulsive force // use Runge Kutta to integrate eqns var[0]=app.ball1.x; var[1]=app.ball1.vx; var[2]=app.ball1.y; var[3]=app.ball1.vy; t=0.0; dt=0.01; rk4(var,new_var,t,dt); app.ball1.x=new_var[0]; app.ball1.vx=new_var[1]; app.ball1.y=new_var[2]; app.ball1.vy=new_var[3]; // collisions with edges handled by reversing component of velocity // perpendicular to wall if(app.ball1.x>XMAX) app.ball1.vx=-app.ball1.vx; if(app.ball1.y>YMAX) app.ball1.vy=-app.ball1.vy; if(app.ball1.x