Examine the incomplete application code at Rectangle Bound C

Examine the incomplete application code at Rectangle Bound Code below This application should display a rectangle. As the window is resized, the rectangle should change size as well.

Write the code that will set the fill color of rect to light sky blue (one of the predefined colors in JavaFX). This will replace comment *A*.

Write the code that will set the outline color of rect to deep sky blue (one of the predefined colors in JavaFX). This will replace comment *B*.

Write the code that will set the outline width of rect to 5. This will replace comment *C*.

Write the code that will bind the x property of the rectangle rect to one fourth the width property of the pane p. This will replace comment *D*.

Write the code that will bind the y property of the rectangle rect to one fourth the height property of the pane p. This will replace comment *E*.

Write the code that will bind the width property of the rectangle rect to one half the width property of the pane p. This will replace comment *F*.

Write the code that will bind the height property of the rectangle ret to one half the height property of the pane p. This will replace comment *G*.

Solution

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class Main extends Application {

@Override
public void start(Stage stage) {
Group root = new Group();
Scene scene = new Scene(root, 500, 500);
stage.setScene(scene);
stage.setTitle(\"\");

VBox vb = new VBox();

Pane canvas = new Pane();
  
canvas.setPrefSize(500,500);
canvas.setMaxWidth(800);
canvas.setMaxHeight(800);
  
Rectangle rectangle = new Rectangle((int)(canvas.getMaxWidth()*1/4),
(int)(canvas.getMaxHeight()*1/4),
(int)(canvas.getMaxWidth()*1/2),(int)(canvas.getMaxWidth()*1/2));
rectangle.setFill(Color.SKYBLUE);
  
System.out.println(canvas.getMaxHeight());
System.out.println(canvas.getMaxWidth());
  
  
  
rectangle.relocate(70,70);
canvas.getChildren().add(rectangle);
  
vb.getChildren().add(canvas);
  
scene.setRoot(vb);
stage.show();
}

public static void main(String[] args) {
launch(args);
}
}

Examine the incomplete application code at Rectangle Bound Code below This application should display a rectangle. As the window is resized, the rectangle shoul
Examine the incomplete application code at Rectangle Bound Code below This application should display a rectangle. As the window is resized, the rectangle shoul

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site