我在使用fxml表格时圈了一圈。现在,我想通过单击按钮移动该圆圈。这很简单而且很有效,但是当我点击按钮时,我希望在原始图像的相同位置保持相同的圆圈。
private void click0(javafx.event.ActionEvent event) {
Circle c0d = c0;
c0d.setCenterX(600);
c0d.setCenterY(900);
c0d.setRadius(32.0f);
TranslateTransition translate = new TranslateTransition(
Duration.millis(750));
translate.setToX(1);
translate.setToY(432);
ParallelTransition transition = new ParallelTransition(c0,translate);
transition.setCycleCount(1);
transition.play();
}
我可以使用原始属性创建一个圆的新实例,但是如何在与原始属性相同的位置绘制它?
答案 0 :(得分:0)
你可以试试这个:
import javafx.animation.*;
import javafx.application.Application;
import javafx.event.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Circles extends Application {
Group root;
Scene scene;
Button button;
@Override
public void start(Stage s) {
root = new Group();
scene = new Scene(root, 250, 350);
button = new Button();
button.setText("create circle");
root.getChildren().add(button);
s.setScene(scene);
s.show();
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
Circle r = new Circle();
r.setCenterX(90f);
r.setCenterY(90f);
r.setRadius(32.0f);
r.setFill(Color.ORANGE);
TranslateTransition translate = new TranslateTransition(
Duration.millis(5000));
translate.setToX(1);
translate.setToY(432);
ParallelTransition transition = new ParallelTransition(r,translate);
transition.setCycleCount(1);
transition.play();
root.getChildren().add(r);
}
});
}
public static void main(String args[]) {
Application.launch(args);
}
}