Advertisement
Guest User

Scalable RED Stripes

a guest
Mar 20th, 2017
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. // Antonio Silvestri
  2. // 03/20/17
  3. // Scalable Red Stripes
  4.  
  5. package chapter14;
  6.  
  7. import javafx.application.Application;
  8. import javafx.scene.Scene;
  9. import javafx.scene.layout.Pane;
  10. import javafx.scene.paint.Color;
  11. import javafx.scene.shape.Rectangle;
  12. import javafx.stage.Stage;
  13.  
  14. public class Stripes extends Application {
  15.     @Override // Override the start method in the Application class
  16.     public void start(Stage primaryStage) {
  17.         Pane pane = new Pane();
  18.         final double PANEWIDTH = 570;
  19.         final double PANEHEIGHT = 310;
  20.  
  21.         for (int i = 0; i < 7; i++) {
  22.             Rectangle r = new Rectangle();
  23.             r.setX(10);
  24.             r.widthProperty().bind(pane.widthProperty().subtract(20));
  25.             r.yProperty().bind(pane.heightProperty().subtract(20).divide(13).multiply(2*i).add(10));
  26.             r.heightProperty().bind(pane.heightProperty().subtract(20).divide(13.0));
  27.             r.setFill(Color.RED);
  28.             pane.getChildren().addAll(r);
  29.         }
  30.  
  31.         // Create a scene and place it in the stage
  32.         Scene scene = new Scene(pane, PANEWIDTH, PANEHEIGHT);
  33.         primaryStage.setTitle("Red Stripes");
  34.         primaryStage.setScene(scene);
  35.         primaryStage.show();
  36.     }
  37.  
  38.     /**
  39.      * The main method is only needed for the IDE with limited JavaFX support.
  40.      * Not needed for running from the command line.
  41.      */
  42.     public static void main(String[] args) {
  43.         launch(args);
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement