- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to implement ActionEvent using method reference in JavaFX?
The javafx.event package provides a framework for Java FX events. The Event class serves as the base class for JavaFX events and associated with each event is an event source, an event target, and an event type. An ActionEvent widely used when a button is pressed.
In the below program, we can implement an ActionEvent for a button by using method reference.
Example
import javafx.application.*; import javafx.beans.property.*; import javafx.event.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; import javafx.scene.effect.*; public class MethodReferenceJavaFXTest extends Application { private Label label; public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { Pane root = new StackPane(); label = new Label("Method Reference"); Button clickMe = new Button("Click Me"); clickMe.setOnAction(this::handleClickMe); // method reference root.getChildren().addAll(label, clickMe); primaryStage.setTitle("Method Reference Test"); primaryStage.setScene(new Scene(root, 300, 200)); primaryStage.show(); } private void handleClickMe(ActionEvent event) { if(label.getEffect() == null) { label.setEffect(new BoxBlur()); } else { label.setEffect(null); } } }
Output
- Related Articles
- How to implement LongPredicate using lambda and method reference in Java?
- How to implement LongSupplier using lambda and method reference in Java?
- How to implement DoubleUnaryOperator using lambda and method reference in Java?
- How to implement DoublePredicate using lambda and method reference in Java?
- How to implement LongBinaryOperator using lambda and method reference in Java?
- How to implement LongFunction using lambda and method reference in Java?
- How to implement DoubleSupplier using lambda and method reference in Java?
- How to implement IntToDoubleFunction using lambda and method reference in Java?
- How to implement IntToLongFunction using lambda and method reference in Java?
- How to implement LongToIntFunction using lambda and method reference in Java?
- How to implement LongToDoubleFunction using lambda and method reference in Java?
- How to implement an action listener using method reference in Java?
- How to implement DoubleBinaryOperator using lambda and method reference in Java?
- How to implement IntConsumer using lambda and method reference in Java?\n
- How to implement ToIntFunction using lambda and method reference in Java?\n

Advertisements