public void actionPerformed (ActionEvent event) {  // like simulate method of Assignment 1, 
      double nextStop=t+refreshPeriod;                // the arguments are attributes here.
      double Ek=0,Ep=0;
      Ball bola;
      Spring resorte;
      for (; t<nextStop; t+=delta_t){
          Ek=0; Ep=0;
         for (PhysicsElement e: elements) //aqui deberia meter los cambios en los arreglos de energia
            if (e instanceof Simulateable) {
               Simulateable s = (Simulateable) e;
               s.computeNextState(delta_t,this); // compute each element next state based on current global state
            }
         for (PhysicsElement e: elements){  // for each element update its state.
            if (e instanceof Simulateable) {
               Simulateable s = (Simulateable) e;
               s.updateState();            // update its state
               if (e instanceof Ball ){
					bola=(Ball)e;
					// Sumatoria de Energia Cinetica de todas las bolas
					Ek += (bola.getMass()/2)*(bola.getSpeed()*bola.getSpeed());//.moduleSquared());
         		}
            }
            if (e instanceof Spring){
               // sumatoria de Energia Potencial de los resortes
                                        resorte =(Spring) e;
					Ep += (resorte.getStiffness()/2)*(resorte.getStretch()*resorte.getStretch());
               }
          }
         }
      grafico.add(Ek,Ep,(float)t,(float)refreshPeriod); 
      repaintView();
   }