GRAPHICAL USER INTERFACE (GUI) USING JAVAFX
14 / 17 1 / 17
GRAPHICAL USER INTERFACE (GUI) USING JAVAFX 14 / 17 1 / 17 WHAT - - PowerPoint PPT Presentation
GRAPHICAL USER INTERFACE (GUI) USING JAVAFX 14 / 17 1 / 17 WHAT IS A GRAPHICAL INTERFACE (GUI)? A GUI is important for anyone who isnt a programmer to use your software! Imagine if everyone had to type their interactions with a PC in a
14 / 17 1 / 17
1 / 17 2 / 17
2 / 17 3 / 17
14 / 17 4 / 17
14 / 17 5 / 17
The Stage is the main container which is usually a Window with a border and the typical minimize, maximize and close buttons. Inside the Stage you add a Scene which can, of course, be switched out by another Scene. Inside the Scene the actual JavaFX nodes like AnchorPane, TextBox, etc. are added.
14 / 17 6 / 17
3 / 17 7 / 17
import javafx.application.Application extend the Application class JavaFX creates an application thread for running the application start method, processing input events, etc. You must override the start(Stage) method
import javafx.stage.Stage This is the top level JavaFX container -- the main window of the application
4 / 17 8 / 17
JavaFX Java GUI Tutorial - 1 - Creating a Basic Window JavaFX Java GUI Tutorial - 1 - Creating a Basic Window
5 / 17 9 / 17
public class HelloWorld extends Application { public static void main(String[] args) { launch(args); // static method of Application which creates Application // this starts the GUI thread and calls Application.start(stage) } @Override public void start(Stage stage) { // override this with your GUI stuff initUI(stage); } private void initUI(Stage stage) { // sets the stage and scene // scene is a tree/graph of nodes; nodes = all visual components of the Label label = new Label("Hello World!!"); VBox root = new VBox(); // LAYOUT - organizes how your subtrees appear root.setPadding(new Insets(5)); root.getChildren().add(label); Scene scene = new Scene(root, 280, 200); // SCENE stage.setTitle("Hello World JavaFX"); stage.setScene(scene); stage.show(); }
6 / 17 10 / 17
7 / 17 11 / 17
https://docs.oracle.com/javase/8/javafx/api/javafx/event/Event.html https://docs.oracle.com/javase/8/javafx/api/javafx/event/EventHandler.html
8 / 17 12 / 17
JavaFX Java GUI Tutorial - 2 - Handle User Events JavaFX Java GUI Tutorial - 2 - Handle User Events
9 / 17 13 / 17
10 / 17 14 / 17
11 / 17 15 / 17
12 / 17 16 / 17
13 / 17 17 / 17