Part 3: Write a JavaFX program that allows a user to moves a rectangle UP, DOWN, LEFT or RIGHT using the arrow keys. Move a rectangle Discuss: 1. Which of the following registrations methods can you use to register an EventHandler by the rectangie object for this program? setOnkeyPressed, setOnkeyReleased or setOnkeyTyped 2. Since you are going to use keys, how you can move the focus to the rectangle? Is using the rectangle object's setfocusTraversable(true) method would help you? 3. How can you determine which arrow keys is pressed? Is using the KeyEvent object's getCode() method would help you? Do you need to compare the returned value by getCode() with one of the four arrow keys' constants in the KeyCode class? 4. If the pressed arrow key is Up or Down, which rectangle coordinate you should update? X or Y ( setx or setY method ). 5. If the pressed arrow key is Left or Right, which rectangle coordinate you should update? X or Y( setX or setY method). Part of the UML diass diagram of KeyEvent class along with part of KeyCode class's constants list are given in the next page.

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 3:
Write a JavaFX program that allows a user to moves a rectangle UP, DOWN, LEFT or RIGHT
using the arrow keys.
Move a rectangle
Discuss:
1. Which of the following registrations methods can you use to register an
EventHandler by the rectangle object for this program?
setOnkeyPressed, setOnkeyReleased or setOnkeyTyped
2. Since you are going to use keys, how you can move the focus to the
rectangle? Is using the rectangle object's setfocusTraversable(true) method
would help you?
3. How can you determine which arrow keys is pressed? Is using the KeyEvent
object's getCode() method would help you? Do you need to compare the
returned value by getCode() with one of the four arrow keys' constants in the
KeyCode class?
4. If the pressed arrow key is Up or Down, which rectangle coordinate you
should update? X or Y ( setX or setY method ).
5. If the pressed arrow key is Left or Right, which rectangle coordinate you
Part of the UML class diagram of KeyEvent class along with part of KeyCode
class's constants list are given in the next page.
Transcribed Image Text:Part 3: Write a JavaFX program that allows a user to moves a rectangle UP, DOWN, LEFT or RIGHT using the arrow keys. Move a rectangle Discuss: 1. Which of the following registrations methods can you use to register an EventHandler by the rectangle object for this program? setOnkeyPressed, setOnkeyReleased or setOnkeyTyped 2. Since you are going to use keys, how you can move the focus to the rectangle? Is using the rectangle object's setfocusTraversable(true) method would help you? 3. How can you determine which arrow keys is pressed? Is using the KeyEvent object's getCode() method would help you? Do you need to compare the returned value by getCode() with one of the four arrow keys' constants in the KeyCode class? 4. If the pressed arrow key is Up or Down, which rectangle coordinate you should update? X or Y ( setX or setY method ). 5. If the pressed arrow key is Left or Right, which rectangle coordinate you Part of the UML class diagram of KeyEvent class along with part of KeyCode class's constants list are given in the next page.
javafx.scene.input.KeyEvent
+getCharacter0: String
+getCode (): KeyCode
+get Text(): String
+isAltDown (): boolean
+iscontrolDown (): boolean
+isMetaDown (): boolean
+isShiftDown (): boolean
Returns the character associated with the key in this event.
Returns the key code associated with the key in this event.
Returns a string describing the key code.
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.
Figure 15.12, Liong, Introduction to Java Programming, Tenth Edition, 2015, Pearson Education
Constant
Description
Constant
Description
HOME
The Home key
CONTROL
The Control key
END
The End key
SHIFT
The Shift key
PAGE UP
The Page Up key
BACK SPACE The Backspace key
PAGE DOMN
The Page Down key
The up-amow key
CAPS
The Caps Lock key
UP
NUM LOCK
The Num Lock key
DOWN
The down-amow key
ENTER
The Enter key
LEFT
The left-arrow key
UNDEFINED
The keyCode unknown
RIGHT
The right-arrow key
Fl to F12
The function keys from Fl to F12
ESCAPE
The Esc key
O to 9
The number keys from 0 to 9
The Tab key
A to Z
The letter keys from A to Z
TAB
TABLE 15.2, Liang, Introduction to java Programming, Tenth Edition, 2015, Pearson Education
Transcribed Image Text:javafx.scene.input.KeyEvent +getCharacter0: String +getCode (): KeyCode +get Text(): String +isAltDown (): boolean +iscontrolDown (): boolean +isMetaDown (): boolean +isShiftDown (): boolean Returns the character associated with the key in this event. Returns the key code associated with the key in this event. Returns a string describing the key code. 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. Figure 15.12, Liong, Introduction to Java Programming, Tenth Edition, 2015, Pearson Education Constant Description Constant Description HOME The Home key CONTROL The Control key END The End key SHIFT The Shift key PAGE UP The Page Up key BACK SPACE The Backspace key PAGE DOMN The Page Down key The up-amow key CAPS The Caps Lock key UP NUM LOCK The Num Lock key DOWN The down-amow key ENTER The Enter key LEFT The left-arrow key UNDEFINED The keyCode unknown RIGHT The right-arrow key Fl to F12 The function keys from Fl to F12 ESCAPE The Esc key O to 9 The number keys from 0 to 9 The Tab key A to Z The letter keys from A to Z TAB TABLE 15.2, Liang, Introduction to java Programming, Tenth Edition, 2015, Pearson Education
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

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