import javax.swing.Timer; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class Simulator implements ActionListener { private BlockSpringConfiguration bsConfig; private float t; // Simulation time time private Timer pase; private float delta_t; // in seconds private float samplingPeriod; // in seconds public Simulator (BlockSpringConfiguration bsc) { t=0; bsConfig = bsc; delta_t = 0.0001f; // 0,1 [ms] samplingPeriod = 0.08f; // 80 [ms] } public void setDelta_t(float delta) { delta_t = delta; } public void setSamplingPeriod (float sp) { samplingPeriod = sp; if (pase!=null) if (pase.isRunning()){ stop(); start(); } } public void start() { t=0; stop(); // pase = new Timer((int)(samplingPeriod*1000/10), this); I used it // to speed the time up and reach the problem sooner. pase = new Timer((int)(samplingPeriod*1000), this); pase.start(); } public void stop(){ if (pase!=null) pase.stop(); } public void actionPerformed (ActionEvent e) { float nextStop=t+samplingPeriod; for (; t