PLEASE, ALSO I NEED THE OPTIONAL TAKS. THANK YOU GUYS The EXTENDED due date for
ID: 3834491 • Letter: P
Question
PLEASE, ALSO I NEED THE OPTIONAL TAKS. THANK YOU GUYS
The EXTENDED due date for this project is Sunday,April 30, 2017. Simple Drawing Application This project involves writing a JavaFX application which draws short line segments in response to the user typing the arrow keys on the keyboard. The line starts from the center of the pane and draws in the direction conresponding to which arrow key the user types: RIGHT, UP, LEFT, or DOWN. If the user types the DELETE key, then all line segments should be erased. The KeyCode constants are defined in the eyCode class. Optional (extra credit) Enhancement(s) 1. "Move" vs. "Draw" If you have time, and would like to try an additional feature, consider this idea: Normally, your code to service the arrow keys will DRAW a line segment in response to the key typed. You could also add a feature where, ifthe user holds down the SHIFT key while hitting an arrow key, then the code does a MOVE to the new X,Yposition, without actually drawing anything. Then, if the user typesanother (unshifted) arrow key, the next line segment will be drawn starting at the new location. 2. If you have another enhancement in mind, please discuss it with me after class, so we can agree on a reasonable scope for the project. A sample of the display is shown below, with optional Enhancement #I implemented D CIT-239 Project 3 SolutionExplanation / Answer
Hi I have executed the below code succesfully.
package javafxapplication;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
/**
*
*
* (Draw lines using the arrow keys)
* Write a program that draws line segments using the arrow keys.
* The line starts from the center of the pane and draws toward east,
* north, west, or south when the right-arrow key, up-arrow key,
* left- arrow key, or down-arrow key is pressed,
*
*/
public class JavaFxApplication extends Application {
Pane pane = new Pane();
double w = 400;
double h = 400;
double cX = w / 2;//width
double cY = h / 2;//height
public void start(Stage primaryStage) {
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() {
pane.getChildren().add(new Line(cX, cY, cX, cY - 10));
cY -= 10;
}
private void moveDown() {
pane.getChildren().add(new Line(cX, cY, cX, cY + 10));
cY += 10;
}
private void moveLeft() {
pane.getChildren().add(new Line(cX, cY, cX - 10, cY));
cX -= 10;
}
private void moveRight() {
pane.getChildren().add(new Line(cX, cY, cX + 10, cY));
cX += 10;
}
public static void main(String[] args) {
Application.launch(args);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.