标签的JavaFX打字机效果

问题描述:

我对这种方法有一些疑问.它工作正常,但有一个小问题.我称之为这种方法的时间太少了.因此只有最后一个字符串会打印在标签上.但我希望下一个字符串开始打印,仅在上一个字符串完成之后. 对不起,我的英语((

i have some problem with this method. it works fine, but with one little problem. there is too little time among i call this method. so only the last String is printed on a label. but i want that the next String starting printed, only after previous String is finished. Sorry for my English((

 public void some(final String s) {

    final Animation animation = new Transition() {
        {
            setCycleDuration(Duration.millis(2000));
        }

        protected void interpolate(double frac) {


            final int length = s.length();
            final int n = Math.round(length * (float) frac);
            javafx.application.Platform.runLater(new Runnable() {
                @Override
                public void run() {

                    status.setValue(s.substring(0, n));

                }
            }
            );
        }

    };

    animation.play();

}

使用以下代码获得打字效果.

Use the following code to get a typewriting effect.

public void AnimateText(Label lbl, String descImp) {
    String content = descImp;
    final Animation animation = new Transition() {
        {
            setCycleDuration(Duration.millis(2000));
        }

        protected void interpolate(double frac) {
            final int length = content.length();
            final int n = Math.round(length * (float) frac);
            lbl.setText(content.substring(0, n));
        }
    };
    animation.play();

}