Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a JavaFx program with a circle in it. Circle has radius of 75 pixels On M

ID: 3827789 • Letter: C

Question

Create a JavaFx program with a circle in it. Circle has radius of 75 pixels

On Mouse press, move circle to the mouse x, y position

On UP key press, move circle up 2 pixels

On DOWN key press, move circle down 2 pixels

on LEFT key press, move circle left 2 pixels

on RIGHT key press, move circle right 2 pixels

Circle should continuously fade from dark green to white and back

Circle should resize on pane resize.

Thanks!

Explanation / Answer

import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.scene.shape.Circle; import javafx.stage.Stage; public class extends Application { double width = 400; double height = 400; double cX = width / 2; double cY = height / 2; Circle c = new Circle(cX, cY, Math.min(width, height) / 10); public void start(Stage primaryStage) { Pane pane = new Pane(c); pane.setOnKeyPressed(e -> { switch (e.getCode()) { case UP: moveUp(); break; case DOWN: moveDown(); break; case LEFT: moveLeft(); break; case RIGHT: moveRight(); break; } }); primaryStage.setScene(new Scene(pane, width, height)); primaryStage.setTitle("Click to see position.."); primaryStage.show(); pane.requestFocus(); } private void moveUp() { c.setCenterY(cY -= 10); } private void moveDown() { c.setCenterY(cY += 10); } private void moveLeft() { c.setCenterX(cX -= 10); } private void moveRight() { c.setCenterX(cX += 10); } public static void main(String[] args) { Application.launch(args); } }