我如何使用变量"t“,它在数学模式中包含在一个构造器参数中。"t“对应于使图表向右移动的时间。
public void update(final Scene scene) {
final Group root = (Group) scene.getRoot();
final Chart chart = new Chart(x -> Math.exp(-(Math.pow((x-t ), 2)))
* Math.cos((2*Math.PI*(x-t))/l),
-1, 1, 0.01,
new Axes(1000, 1000, -1, 1, 0.1, -1, 1, 0.1)
);
root.getChildren().add(chart);
Timeline timeLine = new Timeline(Timeline.INDEFINITE,
new KeyFrame(new Duration(1000),
x -> {}));
timeLine.setAutoReverse(true);
timeLine.play();
}如果我可以在KeyFrame中这样做,就可以解决我的问题。但不能。
while(t < 1) {
t+=0.05;
chart = new Chart(x -> Math.exp(-(Math.pow((x-t ),2)))*Math.cos((2*Math.PI*(x-t))/l),
-1, 1, 0.01, new Axes(1000, 1000,
-1, 1, 0.1, -1, 1, 0.1)
);
}发布于 2016-02-19 20:51:17
您可以在lambda表达式中访问的唯一局部变量是final或有效的最终变量。由于t是经过修改的(t+=0.05),因此它既不是最终版本,也不是有效的最终版本。
您需要做的就是将其值复制到最后一个变量:
while(t < 1) {
t+=0.05;
final double thisT = t ;
chart = new Chart(x -> Math.exp(-(Math.pow((x-thisT ),2)))*Math.cos((2*Math.PI*(x-thisT))/l),
-1, 1, 0.01, new Axes(1000, 1000,
-1, 1, 0.1, -1, 1, 0.1)
);
}https://stackoverflow.com/questions/35504904
复制相似问题