1 import javafx.application.Application;
2 import javafx.scene.Scene;
3 import javafx.scene.layout.Pane;
4 import javafx.scene.paint.Color;
5 import javafx.scene.shape.Rectangle;
6 import javafx.stage.Stage;
7
8 public class TranslationDemo extends Application {
9 @Override
10 public void start(Stage primaryStage) {
11 Pane pane = new Pane();
12
13 double x = 10;
14 double y = 10;
15 java.util.Random random = new java.util.Random();
16 for (int i = 0; i < 10; i++) {
17 Rectangle rectangle = new Rectangle(10, 10, 50, 60);
18 rectangle.setFill(Color.WHITE);
19 rectangle.setStroke(Color.color(random.nextDouble(),
20 random.nextDouble(), random.nextDouble()));
21 rectangle.setTranslateX(x += 20);
22 rectangle.setTranslateY(y += 5);
23 pane.getChildren().add(rectangle);
24 }
25
26 Scene scene = new Scene(pane, 300, 250);
27 primaryStage.setTitle("TranslationDemo");
28 primaryStage.setScene(scene);
29 primaryStage.show();
30 }
31
32
33 public static void main(String[] args) {
34 launch(args);
35 }
36 }