-
Notifications
You must be signed in to change notification settings - Fork 0
Mouse listener
The mouse listener is used to interact with your scene via the mouse. This class doesn't need to be initialized. You can access it via the mouseListener
variable in the scene .
This method is used to add an event to the scene. It executes a set of commands if a certain mouse button is pressed.
MouseButtons button:
This is the mouse button you want to be pressed. It uses an enum
named MouseButtons
to simplify the process of adding an mouse button to the event. (e. g. MouseButtons.LEFT_CLICK
)
Predicate<MouseEvent> function:
The set of commands you want to execute (e. g. e -> {System.out.println("Hello")}
).
boolean blocking:
If true: disables all processing of the mouse button. If false: enables all processing of the mouse button.
mouseListener.addEvent(MouseButtons.LEFT_KLICK, e -> {
System.out.println("Left mouse button pressed!");
});
mouseListener.addEvent(MouseButtons.LEFT_KLICK, e -> {
System.out.println("Left mouse button pressed!");
}, true);
This method is used to remove an event in the scene.
MouseButtons button:
This is the mouse button of the event you want to be deleted. It uses an enum
named MouseButtons
to simplify the process of removing an mouse button from the program. (e. g. MouseButtons.LEFT_CLICK
)
//Add an mouse event.
mouseListener.addEvent(MouseButtons.LEFT_KLICK, LClick());
//Remove the mouse event.
mouseListener.deleteEvent(MouseButtons.LEFT_KLICK, LClick());
//The method that gets executed by the mouse event
private void LClick(){
System.out.println("Left mouse button pressed!");
}
This method returns true
if the mouse is inside the window and false
if not.
if(mouseListener.isMouseInside()){
System.out.println("Mouse is inside!");
}
This method returns true
if the specified mouse button is held down and false
if not.
int mouseButton:
The mouse button you want to be held. (e. g. 1
for the left mouse button)
if(mouseListener.isHeld(1)){
System.out.println("Left mouse button is held!");
}
Returns the position of the mouse as a Point
.