Part 2: Write JavaFX a program that allows a user to move Move a rectangle a rectangle using mouse. The program should display a rectangle and allow a user to point the mouse inside the rectangle and drag the rectangle wherever the mouse goes. So the mouse point becomes the center of the rectangle.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Part 2:
Write JavaFX a program that allows a user to move
Move a rectangle
a rectangle using mouse. The program should
display a rectangle and allow a user to point the
mouse inside the rectangle and drag the rectangle
wherever the mouse goes. So the mouse point
becomes the center of the rectangle.
Page 1 of 4
Transcribed Image Text:Part 2: Write JavaFX a program that allows a user to move Move a rectangle a rectangle using mouse. The program should display a rectangle and allow a user to point the mouse inside the rectangle and drag the rectangle wherever the mouse goes. So the mouse point becomes the center of the rectangle. Page 1 of 4
Lab 10
ITDR2104 - Programming
Discuss:
1. Which of the following registration methods can you use to register an
EventHandler by the rectangie object?
setOnMouseDragged, setOnMouseMoved, setOnMouseReleased or
setOnMousePressed
2. How can you check whether the mouse pointer inside the rectangle or not?
Is using contains method in the Rectangle class would help you? How can you
use contains method?
3. How can you get the mouse pointer's x and y coordinates? Is using the
MouseEvent object's getX() and getY() methods would help you?
4. How can you update the x and y coordinates of the rectangle object? Is using
the Rectangle class setX() and setY() methods would help you?
5. How can you get the new x and y coordinates of the rectangle object which
should be equal to the new position of the mouse pointer (MouseEvent
object)?
The x and y coordinates of the rectangle center can be obtained using
x= rectangle.getWidth() / 2
y = rectangle.getHeight() / 2
But you need the new x and y coordinates of the rectangle which depend on the
new position of the mouse pointer (the MouseEvent object e). How can you get
the new x and y coordinates of the rectangle?
newx = (e.getX() - rectangle.getWidth() ) / 2
newY = (e.getY() - rectangle.getHeight()) / 2
Part of the UML class diagram of MouseEvent class are given below.
javafs.scene.input.MouseEvent
+getButton(): MouseButton
Indicates which mouse button has bcen clicked.
+getClickCount (): int
Returns the number of mouse clicks associaled with this event.
+getX(): double
+getYO: double
+getSceneX): double
+getSceneYO: double
+getScreenX(): double
+getScreenY): double
+isAl tDown): boolean
Returns the x-coordinate of the mouse point in the event source node.
Returns the y-coordinate of the mouse point in the event source node.
Returns the a-coordinate of the mouse point in the secne.
Returns the y-coordinate of the mouse point in the soene.
Returns the x-coordinate of the mouse point in the screen.
Returns the y-coordinate of the mouse point in the screen.
Returns true if the Alt key is pressed on this event.
Returns true if the Control key is pressed on this event.
Returns true if the mouse Meta button is pressed on this event.
Returns true if the Shift key is pressed on this event.
+isControlDown(): boolean
+isMetaDown (): boolean
+isShiftDown (O: boolean
Transcribed Image Text:Lab 10 ITDR2104 - Programming Discuss: 1. Which of the following registration methods can you use to register an EventHandler by the rectangie object? setOnMouseDragged, setOnMouseMoved, setOnMouseReleased or setOnMousePressed 2. How can you check whether the mouse pointer inside the rectangle or not? Is using contains method in the Rectangle class would help you? How can you use contains method? 3. How can you get the mouse pointer's x and y coordinates? Is using the MouseEvent object's getX() and getY() methods would help you? 4. How can you update the x and y coordinates of the rectangle object? Is using the Rectangle class setX() and setY() methods would help you? 5. How can you get the new x and y coordinates of the rectangle object which should be equal to the new position of the mouse pointer (MouseEvent object)? The x and y coordinates of the rectangle center can be obtained using x= rectangle.getWidth() / 2 y = rectangle.getHeight() / 2 But you need the new x and y coordinates of the rectangle which depend on the new position of the mouse pointer (the MouseEvent object e). How can you get the new x and y coordinates of the rectangle? newx = (e.getX() - rectangle.getWidth() ) / 2 newY = (e.getY() - rectangle.getHeight()) / 2 Part of the UML class diagram of MouseEvent class are given below. javafs.scene.input.MouseEvent +getButton(): MouseButton Indicates which mouse button has bcen clicked. +getClickCount (): int Returns the number of mouse clicks associaled with this event. +getX(): double +getYO: double +getSceneX): double +getSceneYO: double +getScreenX(): double +getScreenY): double +isAl tDown): boolean Returns the x-coordinate of the mouse point in the event source node. Returns the y-coordinate of the mouse point in the event source node. Returns the a-coordinate of the mouse point in the secne. Returns the y-coordinate of the mouse point in the soene. Returns the x-coordinate of the mouse point in the screen. Returns the y-coordinate of the mouse point in the screen. Returns true if the Alt key is pressed on this event. Returns true if the Control key is pressed on this event. Returns true if the mouse Meta button is pressed on this event. Returns true if the Shift key is pressed on this event. +isControlDown(): boolean +isMetaDown (): boolean +isShiftDown (O: boolean
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY