Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 17 ■ i3D Game Square SeleCtion: uSinG the piCkreSult ClaSS with 3D moDelS


We will not be specifically constructing (instantiating) MouseEvent objects. We’ll use
.setOnMouseClick() event handling constructs, which will do the construction for us, as part of their
functionality. I will include these two overloaded constructor methods here for the sake of completeness,
however. The first constructs a new MouseEvent Event object, with a null source and target, and would look
like the following Java 9 constructor method syntax:


MouseEvent(EventType<? extends MouseEvent> eventType, double x, double y, double screenX, double
screenY, MouseButton button, int clickCount, boolean shiftDown, boolean controlDown,
boolean altDown, boolean metaDown, boolean primaryButtonDown, boolean
middleButtonDown, boolean secondaryButtonDown, boolean synthesized, boolean
popupTrigger, boolean stillSincePress, PickResult pickResult)


The second constructs a new MouseEvent Event object and would look like the following Java syntax:

MouseEvent(Object source, EventTarget target, EventType<? extends MouseEvent> eventType, double
x, double y, double screenX, double screenY, MouseButton button, int clickCount,
boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown, boolean
primaryButtonDown, boolean middleButtonDown, boolean secondaryButtonDown, boolean
synthesized, boolean popupTrigger, boolean stillSincePress, PickResult pickResult)


There are 27 methods that are part of the MouseEvent class to help you control your mouse event
processing. The .copyFor(Object newSource, EventTarget newTarget) MouseEvent method call will copy
the Event object so that it can be used with a different source and target.
The .copyFor(Object newSource, EventTarget newTarget, EventType<? extends MouseEvent>
eventType) MouseEvent method call will also create a copy of the given Event object, with a given
MouseEvent field substituted.
The static MouseDragEvent .copyForMouseDragEvent(MouseEvent e, Object source, EventTarget
target, EventType type, Object gestureSource, PickResult pickResult) method call
will create a copy of a MouseEvent of type MouseDragEvent.
The .getButton() method call will poll the MouseEvent object to see which, if any, of the mouse buttons
was responsible for generating that Event object. The .getClickCount() method call will return the integer
(int) number of mouse clicks that are associated with the Event object.
The .getEventType() method call will return the EventType<? extends MouseEvent> event type for that
Event object. The .getPickResult() method call will return the PickResult object’s information regarding
that pick.
The .getSceneX() method call will return the double value for the horizontal position of the event
relative to the origin of the Scene that contains your MouseEvent’s source. The .getSceneY() method call will
return the double value for the vertical position of the event relative to the origin of the Scene that contains
your MouseEvent’s source.
The .getScreenX() method call will return the double value for the absolute horizontal position of the
event. The .getScreenY() method call will return the double value for the absolute vertical position of the
event.

Free download pdf