Page 1 of 1

Lesson6

Posted: Wed Sep 02, 2020 2:54 pm
by admin
Create the project SimulationApp.
Add osp.jar to the project.

Re: Lesson6

Posted: Wed Sep 02, 2020 3:00 pm
by admin
  1. package simulationapp;
  2. import org.opensourcephysics.controls.AbstractSimulation;
  3. import org.opensourcephysics.controls.SimulationControl;
  4. public class SimulationApp extends AbstractSimulation{
  5. int counter = 0;
  6. public void doStep(){
  7. // does a simulation step
  8. control.println("Counter = "+(counter--));
  9. }
  10. public void initialize(){
  11. counter = control.getInt("counter");
  12. }
  13. public void reset(){
  14. //invoked when reset button is pressed
  15. //allows dt to be changed after initialization
  16. control.setAdjustableValue("counter",100);
  17. }
  18. public static void main(String[] args){
  19. // creates a simulation structure using this class
  20. SimulationControl.createApp(new SimulationApp());
  21. }
  22. }

Re: Lesson6

Posted: Wed Sep 02, 2020 3:02 pm
by admin

Code: Select all

package simulationapp;
import org.opensourcephysics.controls.AbstractSimulation;
import org.opensourcephysics.controls.SimulationControl;
public class SimulationApp extends AbstractSimulation{
int counter = 0;
public void doStep(){
 // does a simulation step
control.println("Counter = "+(counter--));
}
public void initialize(){
counter = control.getInt("counter");
}
public void reset(){
 //invoked when reset button is pressed
 //allows dt to be changed after initialization
control.setAdjustableValue("counter",100);
}
public static void main(String[] args){
// creates a simulation structure using this class
SimulationControl.createApp(new SimulationApp());
}
}

Re: Lesson6

Posted: Wed Sep 02, 2020 3:05 pm
by admin
The screenshot of SimulationApp program.