Question: Use JavaFx to add a gridded background to the program I have provided. The gridded background should look like that of a cartesian plane. Here
Use JavaFx to add a gridded background to the program I have provided. The gridded background should look like that of a cartesian plane.
Here is the program:
import javafx.animation.TranslateTransition; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; import javafx.util.Duration; //Inherit class Application public class Question extends Application { //set hegith and width of the rectangle private static final double W = 500, H = 500; private static final double S = 60; //draw the rectangle public void start(Stage stage) { //make object of rec class and pass the variables into its constructor Rectangle rec = new Rectangle(W / 2 - S / 2,H / 2 - S / 2,S,S); //make object for transition TranslateTransition transition = new TranslateTransition(Duration.millis(500), rec);
//provide fade transition transition.setOnFinished(t -> { rec.setX(rec.getTranslateX() + rec.getX()); rec.setY(rec.getTranslateY() + rec.getY()); rec.setTranslateX(0); rec.setTranslateY(0); }); //create layout Pane root = new Pane(rec); Scene sc = new Scene(root,W,H); //handle mouse event with object e root.setOnMousePressed(e -> { transition.stop(); transition.setToX(e.getX() - S / 2 - rec.getX()); transition.setToY(e.getY() - S / 2 - rec.getY()); transition.playFromStart(); }); stage.setScene(sc); stage.show(); } public static void main(String[] args) { launch(args); } }
Here is what I want the background of the program to look like:

Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
