Lesson4

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

Lesson4

Post by admin »

From now on we will use the ready-made library Open Source Physics Core Library.
You should download this library using the next link
https://easy-english-study.com/osp.jar
and include it in NetBeans everytime before compiling projects
Open NetBeans and right-click on the project name in the Projects tab.
Select Properties.
Select Libraries.
Click the Add Jar/Folder button.
classpath.png
classpath.png (32.11 KiB) Viewed 579 times
Navigate to the directory where the downloaded osp.jar file is.
admin
Site Admin
Posts: 3118
Joined: Wed Dec 11, 2019 8:31 am
Has thanked: 4 times

Re: Lesson4

Post by admin »

Create the project PlotFrameApp.
admin
Site Admin
Posts: 3118
Joined: Wed Dec 11, 2019 8:31 am
Has thanked: 4 times

Re: Lesson4

Post by admin »

  1. package plotframeapp;
  2. import org.opensourcephysics.frames.PlotFrame;
  3. public class PlotFrameApp{
  4. public static void main (String[] args){
  5. PlotFrame frame=new PlotFrame ("x","sin(x)/x","Plot example");
  6. for (int i=1; i<=100; i++){
  7. double x=i*0.2;
  8. frame.append (0,x,Math.sin(x)/x) ;
  9. }
  10. frame.setVisible(true) ;
  11. frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
  12. }
  13. }
admin
Site Admin
Posts: 3118
Joined: Wed Dec 11, 2019 8:31 am
Has thanked: 4 times

Re: Lesson4

Post by admin »

Code: Select all

package plotframeapp;
import org.opensourcephysics.frames.PlotFrame;
public class PlotFrameApp{
public static void main (String[] args){
PlotFrame frame=new PlotFrame ("x","sin(x)/x","Plot example");
for (int i=1; i<=100; i++){
double x=i*0.2;
frame.append (0,x,Math.sin(x)/x) ;
}
frame.setVisible(true) ;
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
}   
}
admin
Site Admin
Posts: 3118
Joined: Wed Dec 11, 2019 8:31 am
Has thanked: 4 times

Re: Lesson4

Post by admin »

The screenshot of PlotFrameApp program.
Attachments
PlotFrameApp.png
PlotFrameApp.png (8.79 KiB) Viewed 578 times
admin
Site Admin
Posts: 3118
Joined: Wed Dec 11, 2019 8:31 am
Has thanked: 4 times

Re: Lesson4

Post by admin »

This program draws points of the function sin(x)/x using the library osp.jar.
Post Reply