0% found this document useful (0 votes)
48 views

16th May Notes - Javafx

This document provides an overview of several JavaFX classes for working with graphics, images, layouts, and events. It describes the Color, Font, Image, ImageView, FlowPane, and GridPane classes for displaying images and formatting text. It also discusses different types of events in JavaFX like mouse, key, scroll, and drag events, and how to define custom events by extending the Event class. Finally, it mentions different ways to register event handlers using inner classes, anonymous inner classes, and lambda expressions.

Uploaded by

Pooja Vyas
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

16th May Notes - Javafx

This document provides an overview of several JavaFX classes for working with graphics, images, layouts, and events. It describes the Color, Font, Image, ImageView, FlowPane, and GridPane classes for displaying images and formatting text. It also discusses different types of events in JavaFX like mouse, key, scroll, and drag events, and how to define custom events by extending the Event class. Finally, it mentions different ways to register event handlers using inner classes, anonymous inner classes, and lambda expressions.

Uploaded by

Pooja Vyas
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Example: Write a simple JavaFX program to bind textfield value with a label to be displayed.

LISTING 14.7 NodeStyleRotateDemo.java


public void start(Stage primaryStage) {
// Create a scene and place a button in the scene
StackPane pane = new StackPane();
Button btOK = new Button("OK");
btOK.setStyle("-fx-border-color: blue;");
pane.getChildren().add(btOK);

pane.setRotate(45);
pane.setStyle( "-fx-border-color: red;
-fx-background-color: lightgray;");

Scene scene = new Scene(pane, 200, 250);


The Color Class
The Color class can be used to create colors.
JavaFX defines the abstract Paint class for painting a node. The javafx.scene.paint.Color

The Font Class


A Font describes font name, weight, and size.
You can set fonts for rendering the text. The javafx.scene.text.Font class
Font font1 = new Font("SansSerif", 16);
Font font2 = Font.font("Times New Roman", FontWeight.BOLD,
FontPosture.ITALIC, 12);

The Image and Image-View class

 The javafx.scene.image.Image class represents a graphical image and is used for loading an
image from a specified filename or a URL.
 The javafx.scene.image.ImageView is a node for displaying an image. An ImageView can
be created from an Image object.

Alternatively, you can create an ImageView directly from a file or a URL as follows:

ImageView imageView = new ImageView("image/us.gif");

OR
new Image("http://www.cs.armstrong.edu/liang/image/us.gif");

Pane pane = new HBox(10);


pane.setPadding(new Insets(5, 5, 5, 5));
Image image = new Image("image/india.png");
pane.getChildren().add(new ImageView(image));

ImageView imageView2 = new ImageView(image);


imageView2.setFitHeight(100);
imageView2.setFitWidth(100);
pane.getChildren().add(imageView2);

ImageView imageView3 = new ImageView(image);


imageView3.setRotate(90);
pane.getChildren().add(imageView3);
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;

FlowPane

GridPane
There are various events in JavaFX i.e. MouseEvent, KeyEvent, ScrollEvent, DragEvent, etc.
We can also define our own event by inheriting the class javafx.event.Event.

The interface javafx.event.EventHandler must be implemented by all the event handlers and
filters.

Registering Handlers and Handling Events – Inner Class, Anonymous Inner


Class, Lambda Expressions
LAMBDA EXPRESSIONS – MOUSE EVENT ,KEY EVENT

KEY EVENT

You might also like