8. วัตถุสิ่งของ

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 8-21  ตัวอย่างโปรแกรมวาดกราฟเส้นโดยใช้คลาส TimeSeries และ LineGraph
import jlab.graphics.DWindow;
public class TestLineGraph {
  public static void main(String[] args) {
    LineGraph g = new LineGraph(300, 200);
    TimeSeries s4 = sinewave(4);
    TimeSeries s1 = sinewave(1);
    g.plot(DWindow.RED, s4);
    g.plot(DWindow.BLACK, s1);
  }
  private static TimeSeries sinewave(int n) {
    TimeSeries s = new TimeSeries();
    for (double x = -10; x <= 10; x+=0.1) {
      double v = 0;
      for (int k = 1; k <= n; k++) v += Math.sin(k * x);
      s.add(v);
    }
    return s;
  }   
}
©2009 S.Prasitjutrakul