
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question

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

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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 2 images

Knowledge Booster
Similar questions
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

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 Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

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
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY