Lesson6

Post Reply
virtualmod
Site Admin
Posts: 2928
Joined: Wed Dec 11, 2019 8:31 am

Lesson6

Post by virtualmod »

Create the project SimulationApp.
Add osp.jar to the project.
virtualmod
Site Admin
Posts: 2928
Joined: Wed Dec 11, 2019 8:31 am

Re: Lesson6

Post by virtualmod »

  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. }
virtualmod
Site Admin
Posts: 2928
Joined: Wed Dec 11, 2019 8:31 am

Re: Lesson6

Post by virtualmod »

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());
}
}
virtualmod
Site Admin
Posts: 2928
Joined: Wed Dec 11, 2019 8:31 am

Re: Lesson6

Post by virtualmod »

The screenshot of SimulationApp program.
Attachments
SimulatioApp.png
SimulatioApp.png (16.98 KiB) Viewed 189 times
Post Reply