Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+28 votes
asked in CSC285_Fall2018 by (100 points)

1 Answer

+8 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 (335 points)
...