public class ShowRectangle extends Application
1:
2: import javafx.application.Application;
3: import javafx.scene.Group;
4: import javafx.scene.Scene;
5: import javafx.scene.layout.BorderPane;
6: import javafx.scene.paint.Color;
7: import javafx.stage.Stage;
8: import javafx.scene.text.Text;
9: import javafx.scene.shape.Rectangle;
10:
11: public class ShowRectangle extends Application {
12: @Override // Override the start method in the Application class
13: public void start(Stage primaryStage) {
14: // Create rectangles
15: Rectangle r1 = new Rectangle(25, 10, 60, 30);
16: r1.setStroke(Color.BLACK);
17: r1.setFill(Color.WHITE);
18: Rectangle r2 = new Rectangle(25, 50, 60, 30);
19: Rectangle r3 = new Rectangle(25, 90, 60, 30);
20: r3.setArcWidth(15);
21: r3.setArcHeight(25);
22:
23: // Create a group and add nodes to the group
24: Group group = new Group();
25: group.getChildren().addAll(new Text(10, 27, "r1"), r1,
26: new Text(10, 67, "r2"), r2, new Text(10, 107, "r3"), r3);
27:
28: for (int i = 0; i < 4; i++) {
29: Rectangle r = new Rectangle(100, 50, 100, 30);
30: r.setRotate(i * 360 / 8);
31: r.setStroke(Color.color(Math.random(), Math.random(),
32: Math.random()));
33: r.setFill(Color.WHITE);
34: group.getChildren().add(r);
35: }
36:
37: // Create a scene and place it in the stage
38: Scene scene = new Scene(new BorderPane(group), 250, 150);
39: primaryStage.setTitle("ShowRectangle"); // Set the stage title
40: primaryStage.setScene(scene); // Place the scene in the stage
41: primaryStage.show(); // Display the stage
42: }
43:
44: /**
45: * The main method is only needed for the IDE with limited
46: * JavaFX support. Not needed for running from the command line.
47: */
48: public static void main(String[] args) {
49: launch(args);
50: }
51: }