0

参考

https://gist.github.com/jewelsea/2658491

这是我的导致错误的代码块(标有*)

    Calendar time = GregorianCalendar.getInstance();
    double second = time.get(Calendar.SECOND);
    double minute = time.get(Calendar.MINUTE);
    double hour   = time.get(Calendar.HOUR);
    double secondStartPos = 6*second;
    double minuteStartPos = 6*minute;
    double hourStartPos   = 30*hour + (0.5*minuteStartPos);

    //Define rotations
    Rotate secondRotate = new Rotate(secondStartPos, 150, 150);
    Rotate minuteRotate = new Rotate(minuteStartPos, 150, 150);
    Rotate hourRotate = new Rotate(  hourStartPos, 150, 150);
    secondHand.getTransforms().add(secondRotate);
    minuteHand.getTransforms().add(minuteRotate);
    hourHand.getTransforms().add(hourRotate);


    //Time line for second
    Timeline secondTime = new Timeline(
    *        new KeyFrame(
             Duration.seconds(60),
    **       new KeyValue(
             secondRotate.angleProperty(),
             360 + secondStartPos ,
             Interpolator.LINEAR
             )
             )
             );

错误是

*构造函数 KeyFrame(Duration, KeyValue) 未定义

**构造函数 KeyValue(DoubleProperty, double, Interpolator) 未定义

我查看了 API 文档

docs.oracle.com/javafx/2/api/javafx/animation/KeyValue.html

http://docs.oracle.com/javafx/2/api/javafx/animation/KeyFrame.html

但无法弄清楚错误是什么。有人可以帮忙吗?

4

1 回答 1

1

您没有导入正确的类:

import javafx.animation.KeyValue;

可能您正在从 JDK 导入其他一些 KeyValue 类(例如 com.sun.org.apache.xml.internal.security.keys.content.KeyValue)。

有一个更新和更高质量的代码版本,您将在此基础上实现

于 2013-10-16T17:51:08.933 回答