Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Antonio Silvestri
- // 03/20/17
- // Scalable Red Stripes
- package chapter14;
- import javafx.application.Application;
- import javafx.scene.Scene;
- import javafx.scene.layout.Pane;
- import javafx.scene.paint.Color;
- import javafx.scene.shape.Rectangle;
- import javafx.stage.Stage;
- public class Stripes extends Application {
- @Override // Override the start method in the Application class
- public void start(Stage primaryStage) {
- Pane pane = new Pane();
- final double PANEWIDTH = 570;
- final double PANEHEIGHT = 310;
- for (int i = 0; i < 7; i++) {
- Rectangle r = new Rectangle();
- r.setX(10);
- r.widthProperty().bind(pane.widthProperty().subtract(20));
- r.yProperty().bind(pane.heightProperty().subtract(20).divide(13).multiply(2*i).add(10));
- r.heightProperty().bind(pane.heightProperty().subtract(20).divide(13.0));
- r.setFill(Color.RED);
- pane.getChildren().addAll(r);
- }
- // Create a scene and place it in the stage
- Scene scene = new Scene(pane, PANEWIDTH, PANEHEIGHT);
- primaryStage.setTitle("Red Stripes");
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- /**
- * The main method is only needed for the IDE with limited JavaFX support.
- * Not needed for running from the command line.
- */
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement