Please, I need what is mark with red! Thank you a lot!!! I need that to study fo
ID: 3835410 • Letter: P
Question
Please, I need what is mark with red! Thank you a lot!!! I need that to study for my finals this week!!!
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 corresponding 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 javaf.seene.input.KeyCode 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 a feature where, if the user holds down the SHELkey while hitting an arrow key, then the code does a MOVE to the new X, Y position, without actually drawing anything. Then, if the user types another (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 CIT 239 Project 3 SolutionExplanation / Answer
package skowronek15; import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.shape.Line; public class DrawLineWithArrowKeys extends Application { double bX = 150; //start x value denote for beginning-X double bY = 150; //start y value denote for beginning-y double eX = 150; //start x value denote for end-x double eY = 150; //start y value denote for end-y double bX2, bY2; //start of next line double segment = 20; //length of segment @Override public void start(Stage primaryStage) { Pane myPane = new Pane(); //create a pane Line line = new Line(bX,bY,eX,eY); //create the starting or initial line line.setStrokeWidth(2); //set width line.setStroke(Color.RED); //set color myPane.getChildren().add(line); //add line to pane line.setOnKeyPressed(e -> { //switch statement to determine what happens when // each key is pressed if (e.getCode().isArrowKey()) { switch (e.getCode()) { case DOWN: bY2 = bY ; //start of next line, bY2 is equal to the start of originating // y-coordinate bY bY += segment;//increment start of first line eY = bY; // end y (eY) coordinate equal to beginning y coordinate (bY) after // it's incremented; Line line2 = new Line(bX,bY2,eX,eY); //create a new line to be drawn; //beginning y coordinate is now bY2; line2.setStrokeWidth(2); line2.setStroke(Color.GREEN); myPane.getChildren().add(line2); break; case UP: bY2 = bY; bY -= segment; eY = bY; Line line3 = new Line(bX,bY2,eX,eY); line3.setStrokeWidth(2); line3.setStroke(Color.GREEN); myPane.getChildren().add(line3); break; case LEFT: bX2 = bX; bX -= segment; eX = bX; Line line4 = new Line(bX2,bY, eX, eY); line4.setStrokeWidth(2); line4.setStroke(Color.GREEN); myPane.getChildren().add(line4); break; case RIGHT: bX2 = bX; bX += segment; eX = bX; Line line5 = new Line(bX2,bY,eX,eY); line5.setStrokeWidth(2); line5.setStroke(Color.GREEN); myPane.getChildren().add(line5); line5.getStrokeLineJoin(); break; default: break; } } }); Scene scene = new Scene(myPane, 300, 300); primaryStage.setTitle("Draw Line with Arrow Keys"); primaryStage.setScene(scene); primaryStage.show(); line.requestFocus(); } public static void main(String[] args) { launch(args); }