2
JMathPlot 라이브러리를 사용하여 간단한 그래프를 생성합니다.이 경우에는 for 루프의 모든 반복에 대해 업데이트되는 3D입니다. 그러나 속도가있는 그것은 내가 갖는 루프 :플롯 업데이트 오류 - JMathPlot
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
내 이해에 AWT 쓰레드와 메인 쓰레드를 따라받지 함께 할 수있는 뭔가입니다
Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException
합니다. 나는 특별한 방법으로 그래픽 쓰레드를 업데이트 할 필요가 있다는 것을 알고있다. 여기에 내 코드가있다. 아무도 내가 오류없이 대충 (repaint, 나는 짐작한다)을 어떻게 업데이트 할 것을 제안 할 수 있다면 그것은 좋을 것이다.
import javax.swing.*;
import org.math.plot.*;
import static java.lang.Math.*;
import static org.math.array.DoubleArray.*;
public class GridPlotsExample {
public static void main(String[] args) throws InterruptedException {
JFrame frame = new JFrame("a plot panel");
frame.setSize(600, 600);
frame.setVisible(true);
// create your PlotPanel (you can use it as a JPanel) with a legend
// at SOUTH
Plot3DPanel plot = new Plot3DPanel("SOUTH");
frame.setContentPane(plot);
for (int i = 1; i < 10; i++) {
// define your data
double[] x = increment(0.0, 0.1, i); // x = 0.0:0.1:1.0
double[] y = increment(0.0, 0.05, i);// y = 0.0:0.05:1.0
double[][] z1 = f1(x, y);
double[][] z2 = f2(x, y);
// add grid plot to the PlotPanel
plot.addGridPlot("z=cos(PI*x)*sin(PI*y)", x, y, z1);
plot.addGridPlot("z=sin(PI*x)*cos(PI*y)", x, y, z2);
}
}
// function definition: z=cos(PI*x)*sin(PI*y)
public static double f1(double x, double y) {
double z = cos(x * PI) * sin(y * PI);
return z;
}
// grid version of the function
public static double[][] f1(double[] x, double[] y) {
double[][] z = new double[y.length][x.length];
for (int i = 0; i < x.length; i++)
for (int j = 0; j < y.length; j++)
z[j][i] = f1(x[i], y[j]);
return z;
}
// another function definition: z=sin(PI*x)*cos(PI*y)
public static double f2(double x, double y) {
double z = sin(x * PI) * cos(y * PI);
return z;
}
// grid version of the function
public static double[][] f2(double[] x, double[] y) {
double[][] z = new double[y.length][x.length];
for (int i = 0; i < x.length; i++)
for (int j = 0; j < y.length; j++)
z[j][i] = f2(x[i], y[j]);
return z;
}
}
답변 해 주셔서 감사합니다. 그러나 내가 게시 한 방식으로 시도하기 전에 시도했지만, 각 반복마다 새로운 Plot3D 패널을 만들지 않고 동일한 플롯을 '새로 고침'하고 싶었습니다. 그것은 실현 가능하지 않습니까? 건배. – ritchie888