模拟时钟小部件javafx的麻烦

时间:2013-10-16 09:57:06

标签: widget javafx clock

参考

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

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

1 个答案:

答案 0 :(得分:1)

您没有导入合适的班级:

import javafx.animation.KeyValue;

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

There is a newer and higher quality version of the code on which you are basing your implementation