Lesson5

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

Lesson5

Post by virtualmod »

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

Re: Lesson5

Post by virtualmod »

  1. package calculationapp;
  2. import org.opensourcephysics.controls.*;
  3. public class CalculationApp extends AbstractCalculation{
  4. public void calculate(){
  5. control.println("Calculation button pressed.");
  6. //String must match argument of set Value
  7. double x = control.getDouble ("x value");
  8. control.println("x*x="+(x*x )) ;
  9. control.println("random="+Math.random());
  10. }
  11. public void reset(){
  12. //describes parameter and sets its value
  13. control.setValue("x value",10.0);
  14. }
  15. //Creates a calculation control structure using this class
  16. public static void main(String[] args){
  17. CalculationControl.createApp(new CalculationApp());
  18. }
  19. }
virtualmod
Site Admin
Posts: 2928
Joined: Wed Dec 11, 2019 8:31 am

Re: Lesson5

Post by virtualmod »

Code: Select all

package calculationapp;
import org.opensourcephysics.controls.*;
public class CalculationApp extends AbstractCalculation{
public void calculate(){ 
control.println("Calculation button pressed.");
//String must match argument of set Value
double x = control.getDouble ("x value");
control.println("x*x="+(x*x)) ;
control.println("random="+Math.random());
}
public void reset(){
//describes parameter and sets its value
control.setValue("x value",10.0);
}
//Creates a calculation control structure using this class
public static void main(String[] args){
CalculationControl.createApp(new CalculationApp());
}
}
virtualmod
Site Admin
Posts: 2928
Joined: Wed Dec 11, 2019 8:31 am

Re: Lesson5

Post by virtualmod »

The screenshot of CalculationApp program.
Attachments
CalculationApp.png
CalculationApp.png (19.05 KiB) Viewed 177 times
Post Reply