Question: Edit this code so it has 3 buttons, one to clear the pane, a button to stop drawing but allow movement, and a button to
Edit this code so it has buttons, one to clear the pane, a button to stop drawing but allow movement, and a button to draw while moving like a pencil going up button and down button If possible make multiple methods so it isn't one start method, will thumbs up thank you.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class ArrowKeyDrawing extends Application
private double x y ;
private double pixels ;
@Override
public void startStage primaryStage
Pane root new Pane;
Canvas canvas new Canvas;
getting a GraphicsContext from canvas
GraphicsContext gc canvas.getGraphicsContextD;
positioning gc to xy
gcmoveTox y;
line thickness
gcsetLineWidth;
adding canvas to root
root.getChildrenaddcanvas;
Scene scene new Sceneroot;
adding key pressed listener
scene.setOnKeyPressede
getting clicked key code
KeyCode c egetCode;
finding clicked key
if c KeyCode.UP
up
gclineTox y pixels;
updating coordinates
y y pixels;
else if c KeyCode.DOWN
down
gclineTox y pixels;
y y pixels;
else if c KeyCode.LEFT
left
gclineTox pixels, y;
x x pixels;
else if c KeyCode.RIGHT
right
gclineTox pixels, y;
x x pixels;
show the drawing
gcstroke;
;
primaryStage.setScenescene;
primaryStage.setTitleDrawing With Arrow Keys";
primaryStage.show;
public static void mainString args
launchargs;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
