Question: 2. The following program draws an BB-8 as shown below. Modify the program to move the BB-8 left or right using the arrow keys. The


2. The following program draws an BB-8 as shown below. Modify the program to move the BB-8 left or right using the arrow keys. The program can be download from the CMS. import javaf x,application.Application; import javaf x, scene. Scene; import javaf x. scene. Input. Keycode; import javaf x. scene. layout. Pane; import javafx. scene.paint. Color; import javafx. scene. shape. circle; import javafx. scene. shape. .ine: import javafx. stage. 5 tage; public class MovingBB8 extends Application \{ Boverride H Override the start method in the Application class public void start(Stage primaryStage) \{ BBaPane pane = new BB8Pane( ) pane.setonkeyPressed(e { II Write your code here \}); I/ Create a scene and place it in the stage Scene scene = new Scene(pane, 400,120); primarystage.setTitle("MovingBB8"); primarystage. setscene (scene)i primarystage.show (); pane. requestfocus () ; 7 class BA8Pane extends Pane \{ private Circle circle1 - new Circle (200,50,15); private circle circle2 - new Circle (200,70,20); private Line line = new Line (200,25,260,35) i class BB8Pane extends Pane \{ private Circle circle1 = new Circle (200,50,15); private Circle circlez = nem Circle (200,70,20); private Line line = new Line(200, 25, 200, 35); public BB8Pane( ) \{ line, setStroke(Color.BLACK); circle1. setFill(Color.CORAL); circle2. setFill(Color.CORAL); getChildren().addAll(circle1, circle2, line); \} public void moveLeft() \{ If Write your code here 7 public void moveRight() ( II write your code here )
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
