Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+32 votes
asked in CSC285_Fall2018 by (1 point)

1 Answer

+9 votes

You'll need to include event handlers for at least mouse press and mouse drag events on your canvas or imageview (depending on your strategy).

For the mouse press event, you'll want to store the x,y for the "starting corner" somewhere.

Then for the mouse drag event, you'll want to draw the rectangle from the startx,startY to the current mouseX,mouseY.

How you draw the rectangle depends on your strategy -- do you want to use a canvas, in which case you use the drawRect method of the GraphicsContext? Or do you want to create a javafx rectangle node which is added to the scene and appears on top of your imageview, and then modify the width/height of that rectangle whenever the mouse is dragged?

answered by (5.7k points)
...