import com.rinearn.graph2d.RinearnGraph2D; import com.rinearn.graph2d.RinearnGraph2DOptionItem; import java.awt.event.WindowListener; import java.awt.event.WindowEvent; public class Sample4 implements Runnable, WindowListener { Thread thread = null; // アニメーション用のスレッド RinearnGraph2D graph = null; // グラフ volatile boolean continuesLoop = true; // ループの継続/終了を制御する public static void main(String[] args) { Sample4 sample = new Sample4(); } // 初期化・実行開始処理 public Sample4() { // グラフを起動し、描画範囲の設定と自動調整機能の無効化を行う this.graph = new RinearnGraph2D(); graph.setXRange(0.0, 10.0); graph.setYRange(-2.5, 2.5); this.graph.setXAutoRangingEnabled(false); this.graph.setYAutoRangingEnabled(false); // データ更新と描画処理の関係を非同期にする(リアルタイムアニメーション用) //(※ 連番で画像出力する用途などでは行わない方がコマ落ちや欠けを防げる) this.graph.setAsynchronousPlottingEnabled(true); // グラフを閉じたら独自終了処理を行うリスナーを登録、デフォルト処理は無効化 this.graph.addWindowListener(this); this.graph.setAutoDisposingEnabled(false); // アニメーションスレッドを生成して実行開始 this.thread = new Thread(this); this.thread.start(); } // アニメーションスレッドの処理 @Override public void run() { int n = 101; double[] x = new double[n]; double[] y = new double[n]; // アニメーションループ(continuesLoopがtrueの間継続) for(int frame=0; this.continuesLoop; frame++) { double t = frame * 0.05; // 時刻変数 // 座標値データを更新してグラフに転送(非同期) for(int i=0; i