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

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. Please use Javafx 

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.input.KeyCode;

import javafx.scene.layout.Pane;

import javafx.scene.paint.Color;

import javafx.scene.shape.Circle;

import javafx.scene.shape.Line;

import javafx.stage.Stage;

public class MovingBB8 extends Application {

     @Override // Override the start method in the Application class

public void start(Stage primaryStage) { 

           BB8Pane pane = new BB8Pane();

           pane.setOnKeyPressed(e -> { 

               // Write code here

           });

           // Create  scene and place it in the stage

           Scene scene = new Scene(pane, 400, 120);

           primaryStage.setTitle(“MovingBB8”);

           primaryStage.setScene(scene);

           primaryStage.show();

           pane.requestFocus();

     }

class BB8Pane 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, 200, 35);

public BB8Pane() {

           line.setStroke(Color.BLACK);

           circle1.setFill(Color.CORAL);

           circle2.setFill(Color.CORAL);

           getChildren().addAll(circle1, circle2, line);

     }

public void moveLeft() {

           // Write  code here

     }

public void moveRight() {

     // write  code here

     }

}

Share This Post

Email
WhatsApp
Facebook
Twitter
LinkedIn
Pinterest
Reddit

Order a Similar Paper and get 15% Discount on your First Order

Related Questions