画布上的JavaFX动画

画布上的JavaFX动画,java,javafx,Java,Javafx,我是Java的新手。我试图制作一个简单的“二叉搜索树”程序。我在制作过程中遇到了问题,所以我正在寻找答案。 当程序在寻找我添加数字的正确位置时,我想在处理过程中使用“闪烁”功能,但它是这样工作的。 (它不是闪烁,而是倍增。) 我怎样才能解决这个问题 这里是我在控制器中编写的“add”方法 public void handleAddAction(ActionEvent event) { System.out.println("add ? ?"); String

我是Java的新手。我试图制作一个简单的“二叉搜索树”程序。我在制作过程中遇到了问题,所以我正在寻找答案。 当程序在寻找我添加数字的正确位置时,我想在处理过程中使用“闪烁”功能,但它是这样工作的。 (它不是闪烁,而是倍增。) 我怎样才能解决这个问题

这里是我在控制器中编写的“add”方法

public void handleAddAction(ActionEvent event) {
   System.out.println("add ?   ?");
   String key = addfield.getText();
   int length = key.length();
   
   if ( length > 0 ) {
      boolean integerornot = isStringInteger(key, 10);
      if ( integerornot == true ) {
          int intkey = Integer.parseInt(key);
          if (bst.size() > 10) {
              Alert maxerror = new Alert(Alert.AlertType.WARNING);
              maxerror.setTitle("Message");
              maxerror.setHeaderText("The maximum number of nodes is 10.");
              maxerror.showAndWait();
           }else if(bst.contains(intkey)!=null) {
              Alert duperror = new Alert(Alert.AlertType.WARNING);
              duperror.setTitle("Message");
              duperror.setHeaderText("Duplicated numbers cannot be added.");
              duperror.showAndWait();
           }else if (intkey>=0 && intkey <= 9) {
               bst.insert(intkey);
               addfield.setText("");
               DoubleProperty x = new SimpleDoubleProperty();
               DoubleProperty y = new SimpleDoubleProperty();
               
               
                  
               compareNode(bst.root,intkey);
               gc.setStroke(Color.rgb(15, 76, 129));
               gc.setFill(Color.WHITE);
               gc.fillOval(width-10, height-15, 25, 25);
               gc.strokeOval(width-10, height-15, 25, 25);
               gc.setFill(Color.rgb(15, 76, 129));
               gc.fillText(key, width, height);
               if(bst.size()>1) {
                  gc.strokeLine(width-ratiowidth, height-50 +(25/2), width-ratiowidth, height -50 +(25/2) +10);
                  gc.strokeLine(width-ratiowidth, height-50 +(25/2)+10, width, height -50 +(25/2) +10);
                  gc.strokeLine(width, height-50 +(25/2) +10, width, height -(25/2));
                  gc.fillPolygon(new double [] {width-5, width, width+5}, new double[] {height -(25/2) -10, height -(25/2), height -(25/2)-10}, 3);
                  
                  Timeline timeline = new Timeline(
                        new KeyFrame(Duration.seconds(0),
                              new KeyValue(x, width-ratiowidth),
                              new KeyValue(y, height-50)
                        ),
                        new KeyFrame(Duration.millis(10),
                              new KeyValue(x, width),
                              new KeyValue(y, height)
                        )
                  );
                  // timeline.setCycleCount(Timeline.INDEFINITE);
                  
                  AnimationTimer timer = new AnimationTimer() {
                     public void handle(long now) {
                        gc.setStroke(Color.BLUE);
                        gc.strokeOval(x.doubleValue(), y.doubleValue(), 30, 30);
                     }
                  } ;
                  
                  timer.start();
                  timeline.play();
               }
               prekey = intkey;
               height = 20;
               width = 740;
               ratiowidth = 740;
           } else {
              Alert inerror = new Alert(Alert.AlertType.WARNING);
              inerror.setTitle("Message");
              inerror.setHeaderText("Only numbers from 0 to 9 can be added.");
              inerror.showAndWait();
           } 
       }else {
          Alert string = new Alert(Alert.AlertType.WARNING);
          string.setTitle("Message");
          string.setHeaderText("Please insert integer.");
          string.showAndWait();
       }
   }else {
      Alert noinput = new Alert(Alert.AlertType.WARNING);
      noinput.setTitle("Message");
      noinput.setHeaderText("You did not input anything! Please insert value.");
      noinput.showAndWait();
   }
   
   addfield.setText("");
   
}
public void handleAddAction(ActionEvent){
System.out.println(“添加”);
String key=addfield.getText();
int length=key.length();
如果(长度>0){
布尔整数rnot=isStringInteger(键,10);
if(integerornot==true){
int intkey=Integer.parseInt(key);
如果(bst.size()>10){
Alert maxerror=新警报(Alert.AlertType.WARNING);
maxerror.setTitle(“消息”);
setHeaderText(“最大节点数为10”);
maxerror.showAndWait();
}如果(bst.contains(intkey)!=null),则为else{
Alert duperror=新警报(Alert.AlertType.WARNING);
duperror.setTitle(“消息”);
setHeaderText(“无法添加重复的数字”);
duperor.showAndWait();
}else if(intkey>=0&&intkey 1){
球茎线(宽比宽度,高-50+(25/2),宽比宽度,高-50+(25/2)+10);
球茎线(宽比宽度,高-50+(25/2)+10,宽,高-50+(25/2)+10);
球茎线(宽,高-50+(25/2)+10,宽,高-(25/2));
gc.fillPolygon(新双[]{width-5,width,width+5},新双[]{height-(25/2)-10,height-(25/2),height-(25/2)-10},3);
时间线=新时间线(
新关键帧(持续时间。秒(0),
新键值(x,宽度比宽度),
新键值(y,高度-50)
),
新关键帧(持续时间为10毫秒),
新键值(x,宽度),
新键值(y,高度)
)
);
//timeline.setCycleCount(timeline.unfinite);
AnimationTimer=新的AnimationTimer(){
公共无效句柄(长){
gc.设定行程(颜色为蓝色);
gc.strokeOval(x.doubleValue(),y.doubleValue(),30,30);
}
} ;
timer.start();
timeline.play();
}
prekey=intkey;
高度=20;
宽度=740;
比值宽度=740;
}否则{
Alert inerror=新警报(Alert.AlertType.WARNING);
错误设置标题(“消息”);
inerror.setHeaderText(“只能添加0到9之间的数字”);
在错误的showAndWait()中;
} 
}否则{
警报字符串=新警报(Alert.AlertType.WARNING);
string.setTitle(“消息”);
setHeaderText(“请插入整数”);
showAndWait();
}
}否则{
Alert noinput=新警报(Alert.AlertType.WARNING);
无输入设置标题(“消息”);
noinput.setHeaderText(“您没有输入任何内容!请插入值”);
noinput.showAndWait();
}
addfield.setText(“”);
}
提前谢谢:)

请。。请