【发布时间】:2015-04-22 05:17:15
【问题描述】:
几天前我已经开始试用 ScalaFX API。要了解此 API 的用法,我正在查看 GitHub 上的示例。为了测试TimeLine 类的特性,我使用了这个例子:ScalaFXAnimation。
示例中定义 TimeLine 对象的代码如下所示:
val timeline = new Timeline {
cycleCount = Timeline.Indefinite
autoReverse = true
keyFrames = Seq(
at (2 s) {rect1.x -> 200d tween Interpolator.EASE_IN},
at (4 s) {rect1.x -> 300d},
at (3 s) {rect2.y -> 100d tween Interpolator.EASE_BOTH},
at (4 s) {rect2.y -> 300d},
at (4 s) {rect2.width -> 300d tween Interpolator.EASE_OUT}
)
}
如果我尝试在自己的项目中执行此操作,我会收到一些编译错误,例如:
Error:(58, 5) not found: value cycleCount
也找不到值autoReverse、keyFrames 和s。
我没有自己设置项目及其结构,而是从 GitHub 克隆了一个“Hello world”项目:scalafx-hello-world。该项目并正确编译。
这可能是 ScalaFX 中的错误吗?你有什么想法可以解决这个问题吗?
EDIT2:完整代码
package hello
import scalafx.animation.{Timeline, Interpolator}
import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.scene.Scene
import scalafx.scene.paint.Color
import scalafx.scene.shape.Rectangle
import scalafx.Includes._
import scala.language.postfixOps
object ScalaFXHelloWorld extends JFXApp {
val rect1 = new Rectangle {
width = 100
height = 200
fill = Color.Red
}
val rect2 = new Rectangle {
width = 200
height = 120
fill = Color.Green
}
val timeline = Timeline {
cycleCount = Timeline.Indefinite
autoReverse = true
keyFrames = Seq(
at (2 s) {rect1.x -> 200d tween Interpolator.EASE_IN},
at (4 s) {rect1.x -> 300d},
at (3 s) {rect2.y -> 100d tween Interpolator.EASE_BOTH},
at (4 s) {rect2.y -> 300d},
at (4 s) {rect2.width -> 300d tween Interpolator.EASE_OUT}
)
}
timeline.play()
stage = new PrimaryStage {
scene = new Scene {
content = List(rect1, rect2)
}
}
}
【问题讨论】:
-
上面的代码直接取自一个正常工作的例子。您的问题可能与包含 JavaFX 而不是 ScalaFX 类有关。你能用“包含”发布一段你有问题的完整代码吗?
-
不,我使用了与示例相同的导入。使用导入对帖子进行了编辑
-
到目前为止您发布的代码看起来不错。虽然这些只是碎片,但问题出在其他地方。您能否发布可用于重现编译错误的完整示例?
-
用完整的源代码再次编辑 - 我认为它与示例中的完全一样