Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 1. The code below will allow a user to draw lines (in red) on a window using their mouse. import javafx.application.Application; import javafx.scene.Scene; import

Exercise 1. The code below will allow a user to draw lines (in red) on a window using their mouse.

import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.Group; import javafx.scene.paint.Color; import javafx.scene.shape.*; import javafx.stage.Stage; import javafx.scene.input.MouseEvent; public class ElasticLines extends Application{ private Line line; private Group root; @Override public void start(Stage primaryStage) { root = new Group(); Scene scene = new Scene(root, 500, 500,Color.LIGHTBLUE); scene.setOnMousePressed(this::processMousePress); scene.setOnMouseDragged(this::processMouseDrag); primaryStage.setTitle("Elastic Lines"); primaryStage.setScene(scene); primaryStage.show(); } public void processMousePress(MouseEvent e){ line = new Line(e.getX(), e.getY(), e.getX(), e.getY()); line.setStroke(Color.RED); line.setStrokeWidth(3); root.getChildren().add(line); } public void processMouseDrag(MouseEvent e){ line.setEndX(e.getX()); line.setEndY(e.getY()); } public static void main(String[] args) { Application.launch(args); } }

image text in transcribed

Here is a sample from this progranm You need to adapt the above code to include at least 4 buttons centered along the top of the window that will allow a user to change the colour of the lines (e.g., red, blue, green, purple). You can have additional buttons if you want. You can use any type of layout to organize this but it must work correctly Here is a sample of what the adapted code will look like: Basse Lines RED BLUE GREEN PURPLE

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_2

Step: 3

blur-text-image_3

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 Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions

Question

2. Do you find change a. invigorating? b. stressful? _______

Answered: 1 week ago