I have a button and I want a text to be displayed when I hover the mouse over the button.
Both of these work but can they be used interchangeably?
// First
EventHandler<MouseEvent> eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
System.out.println("Hello World");
}
};
button.setOnMouseEntered(eventHandler);
// Second. Lambda expression.
button.setOnMouseEntered(e -> {
System.out.println("Hello ");
});
I don't quite understand the first one. I suppose that EventHandler<MouseEvent>
is the type and eventHandler
is the name of the object. Right?