Lesson6

Post Reply
admin
Site Admin
Posts: 3118
Joined: Wed Dec 11, 2019 8:31 am
Has thanked: 4 times

Lesson6

Post by admin »

Create the project SimulationApp.
Add osp.jar to the project.
admin
Site Admin
Posts: 3118
Joined: Wed Dec 11, 2019 8:31 am
Has thanked: 4 times

Re: Lesson6

Post 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. }
admin
Site Admin
Posts: 3118
Joined: Wed Dec 11, 2019 8:31 am
Has thanked: 4 times

Re: Lesson6

Post 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());
}
}
admin
Site Admin
Posts: 3118
Joined: Wed Dec 11, 2019 8:31 am
Has thanked: 4 times

Re: Lesson6

Post by admin »

The screenshot of SimulationApp program.
Attachments
SimulationApp.png
SimulationApp.png (11.95 KiB) Viewed 512 times
Post Reply