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