JavaFX A Crash Course - Elite.polito.it

1y ago
6 Views
1 Downloads
1.32 MB
23 Pages
Last View : 11d ago
Last Download : 3m ago
Upload by : Olive Grimm
Transcription

JavaFX – a Crash Course Tecniche di Programmazione – A.A. 2020/2021

JavaFX applications 2 Tecniche di programmazione A.A. 2020/2021

Application structure Stage: where the application will be displayed (e.g., a Windows’ window) Scene: one container of Nodes that compose one “page” of your application Node: an element in the Scene, with a visual appearance and an interactive behavior. 3 Nodes may be hierarchically nested Tecniche di programmazione A.A. 2020/2021

Nested nodes 4 Tecniche di programmazione A.A. 2020/2021

TextInputControl Nodes family TextArea TextField ColorPicker ComboBox Focus on Panes and Controls ChoiceBox ComboBoxBase ListView MenuBar Control Separator Group Slider TabPane ToolBar Button MenuButton CheckBox ToggleButton Label ButtonBase Parent Labeled Cell TitledPane Axis Region WebView javafx.scene.Node Chart AnchorPane FlowPane HBox TilePane BorderPane GridPane StackPane VBox Pane Arc Line Polyline Circle Polygon Rectangle Text Shape Canvas 5 Imageview Tecniche di programmazione A.A. 2020/2021

Essential Reference JavaFX JavaDoc API JavaFX Class Diagrams https://openjfx.io/javado c/11/ http://falkhausen.de/Java FX-10/index.html 6 Tecniche di programmazione A.A. 2020/2021

Example application structure Extend javafx.application.Application Load scene nodes from XML file Define algorithms and data Populate and show window main() 7 Tecniche di programmazione A.A. 2020/2021

General rules A JavaFX application extends javafx.application.Application The main() method should call Application.launch() The start() method is the main entry point for all JavaFX applications Called with a Stage connected to the Operating System’s window The content of the scene is represented as a hierarchical scene graph of Nodes 8 Stage is the top-level JavaFX container Scene is the container for all content Tecniche di programmazione A.A. 2020/2021

Nodes The Scene is populated with a tree of Nodes Layout components (Panes) UI Controls Charts Shapes Nodes have Properties Visual (size, position, z-order, color, .) Contents (text, value, data sets, .) Programming (event handlers, controller) Nodes generate Events UI events Nodes can be styled with CSS 9 Tecniche di programmazione A.A. 2020/2021

tml Panes 10 Tecniche di programmazione A.A. 2020/2021

olHierarchy.html Controls 11 Tecniche di programmazione A.A. 2020/2021

JavaFX Scene Builder 11 https://gluonhq.com/products/scene-builder/ 12 Tecniche di programmazione A.A. 2020/2021

Building a scene from FXML public void start(Stage stage) throws Exception { Parent root FXMLLoader.load( getClass().getResource("/fxml/Scene.fxml")); stage.setTitle("Circle Demo"); stage.setScene(new Scene(root)); stage.show(); } 13 Tecniche di programmazione A.A. 2020/2021

Key concepts in JavaFX Property: attributes of the Nodes, may specify content, size, color, Can be read and written by the application Event: every user action on one element of the GUI generates a different event. Events can be captured and handled by our code Controller: the Java class that contains 14 References to interesting Nodes Event Handlers Tecniche di programmazione A.A. 2020/2021

Properties Extension of the Java Beans convention Encapsulate properties of an object May be used also outside JavaFX Different types (string, number, object, collection, .) Set/Get Observe changes Support lazy evaluation Each Node has a large set of Properties 15 Can be manipulated The scene updates Tecniche di programmazione A.A. 2020/2021

Events FX Event (javafx.event.Event): Event Source a Node Event Target Event Type Usually generated after some user action Event Types You can define event handlers in your application 16 Tecniche di programmazione A.A. 2020/2021

What is an event? 17 Tecniche di programmazione A.A. 2020/2021

y.html Event types 18 Tecniche di programmazione A.A. 2020/2021

Defining a Controller class The Root element of the scene graph may specify a fx: controller attribute 19 BorderPane id "BorderPane" xmlns:fx "http://javafx.com/fxml" fx:controller "it.polito.tdp.RuzzleController" Tecniche di programmazione A.A. 2020/2021

Injection of Node references The controller code may directly access various Nodes in the associated scene graph The attribute @FXML associates a Node variable with the corresponding node, with the same fx:id value as the variable name Try: View Show Sample Controller Skeleton on the Scene Builder! @FXML // fx:id "theTitle" private Label theTitle; 20 Tecniche di programmazione A.A. 2020/2021

Registration of Event Handlers In FXML, you may set a event handler through attributes onAction, onKeyTyped, onMouseClicked, . hundreds more . The value should be the #name of a method in the controller class With the right signature for the event type Button fx:id "cercaBtn" onAction "#doCercaParola" text "Cerca" / 21 @FXML void doCercaParola ( ActionEvent event ) { Tecniche di programmazione A.A. 2020/2021

Minimal program structure « View » FXML file Nodes (layout controls) Main (load & launch) node properties event handlers « Controller » « Model » Algorithms & Data Structures 22 Tecniche di programmazione A.A. 2020/2021

Licenza d’uso Queste diapositive sono distribuite con licenza Creative Commons “Attribuzione - Non commerciale - Condividi allo stesso modo (CC BY-NC-SA)” Sei libero: Alle seguenti condizioni: di riprodurre, distribuire, comunicare al pubblico, esporre in pubblico, rappresentare, eseguire e recitare quest'opera di modificare quest'opera Attribuzione — Devi attribuire la paternità dell'opera agli autori originali e in modo tale da non suggerire che essi avallino te o il modo in cui tu usi l'opera. Non commerciale — Non puoi usare quest'opera per fini commerciali. Condividi allo stesso modo — Se alteri o trasformi quest'opera, o se la usi per crearne un'altra, puoi distribuire l'opera risultante solo con una licenza identica o equivalente a questa. http://creativecommons.org/licenses/by-nc-sa/3.0/ 23 Tecniche di programmazione A.A. 2020/2021

General rules 8 Tecniche di programmazione A.A. 2020/2021 A JavaFX application extends javafx.application.Application The main() method should call Application.launch() The start() method is the main entry point for all JavaFX applications Called with a Stage connected to the Operating System's window The content of the scene is represented as a hierarchical

Related Documents:

.media - in Default VM Arguments. Note that your JavaFX library location can be different depending on the location that you unzipped. METHOD III: From CMD Prompt: java --module-path "C:\Users\selim\Documents\javafx-sdk-11.0.2\lib" --add-m

This tutorial is a compilation of three documents that were previously delivered with the JavaFX 2.x documentation set: JavaFX Overview, JavaFX Architecture, and Getting Started with JavaFX.

This chapter describes how to add JavaFX co ntent into a Swing application and how to use threads correctly when both Swing and JavaFX content operate within a single application. JavaFX SDK provides the JFXPanel class, which is located in the javafx.embed.swing package and enables you to embed

Oct 10, 2011 · Support for ARM platforms has also been made available with JavaFX 8. JDK for ARM includes the base, graphics and controls components of JavaFX. To install JavaFX install your chosen version of the Java Runtime environment and Java Development kit. Features offered by JavaFX include

Database Operations in JavaFX . At first, part of JavaFX tutorial series, we created a sample JavaFX project, designed the draft version of the UI and set up an Oracle XE database. In this post, we will create controller, model, DAO, and Util classes to do DB operations. Before starting to code, I want to give more information about our example .

What You Will Learn 1 1.1 Background Basics 2 JavaFX Integration 2 1.2 The NetBeans Platform: The Big Picture 3 Module System API 3 . 2.4 Improving the User Experience 63 2.5 Concurrency and Thread Safety 68 . 3.2 Building JavaFX Programs 87 Creating a JavaFX Application 88 Java APIs 88

Swing includes a . JFXPanel. class to embed JavaFX components into a Swing application, and JavaFX includes a . SwingNode. class to embed Swing components into a JavaFX application. Both classes provide corresponding API documentation. Additionally, the official Java documentation site includes an arti

Albert woodfox Arthur Kinoy Award A Message from NYU PILC At every NLG #Law4thePeople Convention, we honor members and friends of the Guild whose exemplary work and activism capture the spirit of “law for the people,” and speak to the Guild’s philosophy of human rights over property interests. Please join us in congratulating our 2016 honorees! Workshops Tentative Schedule Felon .