【发布时间】:2013-10-29 09:46:08
【问题描述】:
Timeline pongAnimation = TimelineBuilder.create()
.keyFrames(
new KeyFrame(
new Duration(10.0),
new EventHandler<ActionEvent>() {
public void handle(javafx.event.ActionEvent t) {
checkForCollision();
int horzPixels = movingRight ? 1 : -1;
int vertPixels = movingDown ? 1 : -1;
centerX.setValue(centerX.getValue() + horzPixels);
centerY.setValue(centerY.getValue() + vertPixels);
}
}
)
)
.cycleCount(Timeline.INDEFINITE)
.build();
这是我正在阅读的书中的 JavaFX 代码。它通过传递Duration 和EventListener 来创建KeyFrame——不多也不少。
与EventHandler 关联的Timeline 类的所有构造函数都需要KeyValues 作为参数。但是,在上面的代码中并非如此。代码编译,甚至给出所需的输出。
为什么?
文档:http://docs.oracle.com/javafx/2/api/javafx/animation/KeyFrame.html
【问题讨论】:
-
这段代码是否符合您的预期取决于
TimelineBuilder类中的内容。您需要查看该类以了解这里发生了什么。
标签: java generics constructor arguments javafx