slam4:javafx

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
slam4:javafx [2016/03/22 00:44] jcheronslam4:javafx [2019/08/31 14:21] (Version actuelle) – modification externe 127.0.0.1
Ligne 1: Ligne 1:
 ====== JavaFx ====== ====== JavaFx ======
 +
 +===== JavaFx application =====
 +
 +JavaFx utilise une analogie avec le théâtre pour bâtir la structure de ses applications.
 +
 +  * Le programme **Main** dérive de **Application**
 +  * Le **Stage** (primaryStage) est le théâtre dans lequel les éléments de l'application vont évoluer, il correspond à la fenêtre
 +  * La **Scene** est l'élément qui permettra de faire apparaître ces éléments, elle correspond au décor ou au lieu de l'action
 +  * La Scene contient un élément parent (noeud Root) qui contient lui même d'autres noeuds  
 +
 +<sxh java>
 +public class Main extends Application {
 + @Override
 + public void start(Stage primaryStage) {
 + try {
 + Scene scene = new Scene(new BorderPane());
 + scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
 + primaryStage.setScene(scene);
 + primaryStage.setTitle("First application JavaFx");
 + primaryStage.show();
 + } catch (Exception e) {
 + e.printStackTrace();
 + }
 + }
 +
 + public static void main(String[] args) {
 + launch(args);
 + }
 +}
 +</sxh>
 +
 +===== Séparation des couches =====
 +
 +Chargement d'une vue à partir d'un fichier fxml :
 +
 +<sxh java;highlight:[4]>
 + @Override
 + public void start(Stage primaryStage) {
 + try {
 + BorderPane root = (BorderPane)FXMLLoader.load(getClass().getResource("Sample.fxml"));
 + Scene scene = new Scene(root,400,400);
 + scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
 + primaryStage.setScene(scene);
 + primaryStage.show();
 + } catch(Exception e) {
 + e.printStackTrace();
 + }
 + }
 +</sxh>
 +
 +<sxh xml;title:Sample.fxml>
 +<?xml version="1.0" encoding="UTF-8"?>
 +
 +<?import javafx.scene.control.Button?>
 +<?import javafx.scene.control.MenuButton?>
 +<?import javafx.scene.control.MenuItem?>
 +<?import javafx.scene.layout.AnchorPane?>
 +<?import javafx.scene.layout.BorderPane?>
 +
 +
 +<BorderPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/9.0.1" fx:controller="application.SampleController">
 +   <top>
 +      <MenuButton mnemonicParsing="false" text="MenuButton" BorderPane.alignment="CENTER">
 +        <items>
 +          <MenuItem mnemonicParsing="false" text="Action 1" />
 +          <MenuItem mnemonicParsing="false" text="Action 2" />
 +        </items>
 +      </MenuButton>
 +   </top>
 +   <center>
 +      <AnchorPane prefHeight="200.0" prefWidth="468.0" BorderPane.alignment="CENTER">
 +         <children>
 +            <Button fx:id="btAdd" layoutX="14.0" layoutY="14.0" mnemonicParsing="false" onAction="#btAddClick" prefHeight="25.0" prefWidth="115.0" text="Button" />
 +         </children>
 +      </AnchorPane>
 +   </center>
 +</BorderPane>
 +</sxh>
 +===== Association d'écouteurs =====
 +Java 8 permet l'utilisation des Lambda expressions :
 +<sxh java>
 +StackPane elem=new StackPane();
 +elem.setOnMouseMouve((e)->{system.out.println("x : "+e.getX()+",y : "+e.getY())});
 +</sxh>
 +
 +===== Bind sur les propriétés d'un objet =====
 +
 +<sxh java>
 + canvas.heightProperty().bind(p.heightProperty());
 +
 +</sxh>
 +===== Remplissage et sélection sur un TableView =====
  
 <sxh java> <sxh java>
Ligne 21: Ligne 113:
 ===== Ressources ===== ===== Ressources =====
 |< 100% >| |< 100% >|
 +| fontawesomefx | [[http://bitbucket.org/Jerady/fontawesomefx]] |
 |jfxtras | [[http://jfxtras.org/]] | |jfxtras | [[http://jfxtras.org/]] |
-|::: | [[http://central.maven.org/maven2/org/jfxtras/jfxtras-labs/8.0-r4/|Download jar]] |+|::: | [[http://central.maven.org/maven2/org/jfxtras/jfxtras-labs/|Download jar]] | 
 + 
 + 
 +===== Articles ===== 
 + 
 +  * [[http://code.makery.ch/blog/javafx-8-event-handling-examples/|event handling]] 
 +  * [[http://code.makery.ch/blog/javafx-dialogs-official/|Dialogs]] 
 +  * [[https://zeroturnaround.com/rebellabs/best-javafx-libraries-for-beautiful-apps-and-clean-code/|Best JavaFx libraries]]
  
  • slam4/javafx.1458603873.txt.gz
  • Dernière modification : il y a 6 ans
  • (modification externe)