Module 3_JavaFX Part A
Module 3_JavaFX Part A
Written in Java
FXML
Scene Builder
Swing Interoperability
Built-in UI Controls
CSS like styling
Integrated Graphics Library
//Creating a Group
Group root = new Group(line);
//Creating a Polygon
Polygon polygon = new Polygon(array);
}
Adding Image
You can load and modify images using the classes provided by JavaFX in the
package javafx.scene.image.
JavaFX supports the image formats like Bmp, Gif, Jpeg, Png.
Loading an Image - You can load an image in JavaFX by instantiating the class
named Image of the package javafx.scene.image.
To the constructor of the class, you have to pass either of the following −
A FileInputStream object of the image to be loaded or,
A string variable holding the URL for the image.
Example
//Passing FileInputStream object as a parameter
FileInputStream inputstream = new FileInputStream("C:\\images\\image.jpg");
Image image = new Image(inputstream);
Package: javafx.scene.control.Button
Constructors
Button b1 = new Button();
Button b2 = new Button("String");
There are two ways of setting the text on the button.
Passing the text into the class constructor
By calling setText("text") method
Wrapping Button Text
Btn.setWrapText(true);
Package: javafx.scene.control.TextField
Constructors
TextField t1 = new TextField();
TextField t2 = new TextField(“Default String");
Methods
t1.setText("text") // set the text in the text field
String str = t1.getText();//retrieves the value of the text field and returns it as a String
t1.setVisible(boolean); // to make the control visible or to hide it
t1.setEditable(boolean);// to make the field editable or not
t1.setDisable(boolean); // to make the field unable to be clicked etc