Question: JavaFx task: This code creates a rectangle that moves where the user clicks. Please create a gridded background for this program . The program should

JavaFx task:

This code creates a rectangle that moves where the user clicks. Please create a gridded background for this program . The program should run like it does now except it should have a gridded background, like the one of a Cartesian plane and like the one I have included.

//import Javafx libraries 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); } }

JavaFx task: This code creates a rectangle that moves where the user

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!