Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a pseudocode, flowchart , and UML diagram: Project12.java import javafx.animation.AnimationTimer; import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent;

Create a pseudocode, flowchart , and UML diagram:

Project12.java

import javafx.animation.AnimationTimer;

import javafx.application.Application;

import javafx.event.EventHandler;

import javafx.scene.Group;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.input.KeyCode;

import javafx.scene.input.KeyEvent;

import javafx.scene.input.Mnemonic;

import javafx.scene.layout.HBox;

import javafx.scene.layout.Pane;

import javafx.scene.layout.StackPane;

import javafx.scene.paint.Color;

import javafx.scene.shape.Ellipse;

import javafx.scene.shape.Polygon;

import javafx.scene.shape.Rectangle;

import javafx.stage.Stage;

public class Project12 extends Application {

//required attributes

int WINDOW_WIDTH = 200;

int WINDOW_HEIGHT = 100;

//initial position

int x = 0;

int y = WINDOW_HEIGHT;

AnimationTimer timer = null;//handles the animation

int MOVING_SPEED = 2; //speed of the car

@Override

public void start(Stage primaryStage) {

/**

* Defining a stack pane to handle both drawing pane and buttons pane

*/

StackPane stackPane = new StackPane();

/**

* creating a pane for drawing the car

*/

Pane drawpane = new Pane();

//drawing car at initial position

drawCar(drawpane);

//adding the pane to stack pane

stackPane.getChildren().add(drawpane);

/**

* creating the required buttons and adding them to an hbox

*/

Button start = new Button("start");

Button stop = new Button("stop");

HBox box = new HBox(start, stop);

box.setSpacing(10);

/**

* adding this hbox into the stack pane

*/

stackPane.getChildren().add(box);

Scene scene = new Scene(stackPane, WINDOW_WIDTH, WINDOW_HEIGHT);

primaryStage.setScene(scene);

primaryStage.show();

/**

* handler for animation timer

*/

timer = new AnimationTimer() {

@Override

public void handle(long now) {

//updating the location

x += MOVING_SPEED;

/**

* checking if the car hits right wall, if yes, starting from

* left

*/

if (x + 50 > primaryStage.getWidth()) {

x = 0;

}

/**

* Drawing the car

*/

drawCar(drawpane);

}

};

/**

* adding action listener to the two buttons

*/

start.setOnAction(new EventHandler() {

@Override

public void handle(javafx.event.ActionEvent event) {

timer.start();

}

});

stop.setOnAction(new EventHandler() {

@Override

public void handle(javafx.event.ActionEvent event) {

timer.stop();

}

});

/**

* adding key pressed listener to detect UP and Down button clicks

*/

stackPane.setOnKeyPressed(new EventHandler() {

@Override

public void handle(KeyEvent event) {

if (event.getCode() == KeyCode.UP) {

//increasing speed

MOVING_SPEED++;

} else if (event.getCode() == KeyCode.DOWN) {

//decreasing speed

MOVING_SPEED--;

if (MOVING_SPEED < 0) {

//setting speed to 0, if the speed goes negative

MOVING_SPEED = 0;

}

}

}

});

}

/**

* method to draw the car and add it to the given pane

*/

public void drawCar(Pane pane) {

pane.getChildren().clear();//removing the existing data

/**

* creating wheels

*/

Ellipse wheel1 = new Ellipse(x + 15, y - 5, 5, 5);

Ellipse wheel2 = new Ellipse(x + 35, y - 5, 5, 5);

/**

* creating body

*/

Rectangle body = new Rectangle(x, y - 20, 50, 10);

body.setFill(Color.BLUE);

/**

* creating upper part of the car

*/

Polygon upperPart = new Polygon(x + 10, y - 20, x + 20, y - 30, x + 30,

y - 30, x + 40, y - 20);

upperPart.setFill(Color.DARKBLUE);

/**

* adding all to a group and then adding the group to the pane

*/

Group group = new Group(wheel1, wheel2, body, upperPart);

pane.getChildren().add(group);

}

public static void main(String[] args) {

launch(args);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago