0% ont trouvé ce document utile (0 vote)
20 vues26 pages

Création d'interfaces JavaFX avec IntelliJ

Le document présente l'API JavaFX, utilisée pour créer des interfaces graphiques, des médias et des animations. Il décrit également le modèle MVC, les concepts de Stage et Scene, ainsi que des instructions pour utiliser IntelliJ et Scene Builder pour développer des applications JavaFX. Enfin, il aborde des éléments comme les alertes, les collections JavaFX et l'utilisation de CSS pour le style des applications.

Transféré par

Borgi Moatez
Copyright
© All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PPTX, PDF, TXT ou lisez en ligne sur Scribd
0% ont trouvé ce document utile (0 vote)
20 vues26 pages

Création d'interfaces JavaFX avec IntelliJ

Le document présente l'API JavaFX, utilisée pour créer des interfaces graphiques, des médias et des animations. Il décrit également le modèle MVC, les concepts de Stage et Scene, ainsi que des instructions pour utiliser IntelliJ et Scene Builder pour développer des applications JavaFX. Enfin, il aborde des éléments comme les alertes, les collections JavaFX et l'utilisation de CSS pour le style des applications.

Transféré par

Borgi Moatez
Copyright
© All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PPTX, PDF, TXT ou lisez en ligne sur Scribd

+

Java FX
PiDev 3A – Sprint
java

1
2

L’API JavaFX
 A partir de Mars 2014, c’est l’outil
officiel de création d’interfaces
graphiques (GUI)

 Création de médias : audio et


vidéos

 Création des animations 2D/3D


+
+ 3

MVC : Model View Controller

 Model: La structure logique des


données

 View: Les interfaces utilisateurs


contenant des éléments
graphiques

 Controller: Assurer la
communication entre les Vues et
les Modèles
4

Stage VS Scene

Stage: Conteneur principal,


habituellement une fenêtre.

Scene: Conteneur des UI


+ elements, associé à un Stage.
+ GUI Java FX
5

XML Avec Java

Button btn = new Button();


<Button id="valider"
fx:id="btn” layoutX="405” [Link]("Say 'Hello World");
layoutY="274”
text="Valider”>

<font>

<Font size="14.0" />

</font>

</Button>
Dans un fichier “.java”
Dans un fichier “.fxml”
+

Hello World
Téléchargez SceneBuilder de :
[Link]
source/scene-builder/
6
+ 7

IntelliJ
NB: Vous devez télécharger la dernière version de l’IDE IntelliJ

File-> Settings -> Languages & Frameworks


Spécifiez le chemin d’installation vers le logiciel « SceneBuilder »


Ouvrez le fichier « [Link] » de votre projet.


Faites un clic droit sur le fichier et sélectionnez l'option « Generate …»


dans le menu contextuel.


+ 8

IntelliJ
- Choisissez « Dependency » dans la liste des options. Cela ouvrira
une fenêtre intitulée « Maven Artifact Search ».

- Dans l'onglet « Search For Artifact », saisissez


«[Link]:javafx-fxml» et choisissez la dernière version
disponible.

- Dans l'onglet « Search For Artifact », saisissez


«[Link]:javafx-controls» et choisissez la dernière version
disponible.

- Appuyez sur le bouton « Load Maven Changes » pour


télécharger et installer automatiquement la bibliothèque dans
votre projet.
+ 9

IntelliJ
Faites un clic droit sur le le dossier « Resources », et créez un

nouveau fichier fxml

Faites un clic droit sur le fichier fxml, et choisissez l’option « Open in


Scene Builder »
+ 10

IntelliJ
Exécution:

Ajoutez ce code dans votre fichier « [Link] »


<build>
<plugins>
<plugin>
<groupId>[Link]</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>[Link]</mainClass>
</configuration>
</plugin>
</plugins>
Remplacez « MainFX » par le nom de votre classe principale

</build>
Appuyez sur le bouton « Load Maven Changes » pour télécharger et installer

automatiquement la bibliothèque dans votre projet.


+ 11

IntelliJ
View -> Tool Windows -> Maven

Plugins -> javafx -> javafx:run



+ 12

Scene Builder
13
Dans le fichier .fxml :

Vous avez
cliqué

Dans le contrôleur (une classe .java) :


public class MyController {
......
@FXML
public void initialize() {

[Link](e->{
[Link](“Vous avez cliqué");
});
}}
+

Navigation
14
15

@FXML
public void naviguerVersAjout(ActionEvent event){

try {
Parent root =
[Link](getClass().getResource("/
[Link]");
[Link]().setRoot(root);
} catch (IOException ex) {
[Link]([Link]());
}
});
+

Insertion
dans la 16
+ 17

[Link](event -> {

Personne p = new Personne([Link](),


[Link]());

PersonneService ps = new PersonneService();

[Link](p);

}
+ Les alertes - Dialogs
18

Information Dialog :

Alert alert = new Alert([Link]);


[Link]("Information Dialog");
[Link]("Personne insérée avec
succés!");
[Link]();
+

TableView
ObservalbleList

19
+ Les Collections javaFX
20

ObsevableList
[i]
Observable [c]
FXCollections

Classe utilitaire :
[i]
ObservableList<E •
> observableArrayList
()

observableHashMa
p()

• ObservalbleList : Une liste qui permet aux


listeners de détécter les changements en temp
réel
21
TableView 22

@FXML
private TableView<Personne> personsTable;
@FXML
private TableColumn<Personne, String> NomColonne;
@FXML
private TableColumn<Personne, String> PrenomColonne;

@FXML
public void initialize() {

PersonneService ps = new PersonneService();

ObservableList<Personne> observableList =
[Link]([Link]);

[Link](observableList);

// Remplir les colonnes :


[Link](cell -> new PropertyValueFactory<>("nom"));

[Link](cell ->new
PropertyValueFactory<>("prenom");

}
+

CSS javaFX

[Link]
/jdk1.8.x/jre/lib/ext/[Link]
com/sun/javafx/scene/control/skin/modena/
23
24

Ajouter un fichier .css

Deux exemples de fichier .css :

• [Link]
• [Link]
+
Graphes
PieChart

25
26

Common questions

Alimenté par l’IA

In JavaFX, FXML files define the user interface structure in a declarative XML format, allowing for cleaner separation of UI from business logic. Controllers, typically defined in separate Java classes, manage the application's behavior by handling user events and interactions specified in the FXML. For example, an FXML file may reference buttons and text fields, while the corresponding controller class sets event handlers to update the application's state or display messages. This model promotes cleaner code organization and facilitates easier maintenance and updates .

JavaFX supports multimedia creation by providing integrated functionalities for audio, video, and animation development within graphical user interfaces. These capabilities include seamless embedding of media content using simple APIs that can handle media playback, control audio and video streams, and support 2D and 3D animations. The framework's compatibility with various media types enhances user engagement through rich and interactive content, making it highly suitable for multimedia-rich applications .

To configure a JavaFX project using IntelliJ IDEA and SceneBuilder, one must first ensure the latest version of IntelliJ is installed. Then, in IntelliJ, navigate to File > Settings > Languages & Frameworks to specify the installation path for SceneBuilder. Open the project's pom.xml file, right-click and select 'Generate...' to open Maven Artifact Search. Search and choose the latest versions of 'org.openjfx:javafx-fxml' and 'org.openjfx:javafx-controls'. Load Maven changes to automatically install libraries. For executions, add specific code to 'pom.xml', replace 'MainFX' with the main class name, and access the 'Maven' tool window to run the project .

JavaFX is the official tool for creating graphic user interfaces (GUI) since March 2014. It includes features for creating media such as audio and video, as well as 2D and 3D animations. JavaFX utilizes a model-view-controller (MVC) structure where the model handles data logic, the view manages user interfaces containing graphical elements, and the controller facilitates communication between the model and view .

In a JavaFX application, the Stage is the main window or container that depicts the visual boundary of the application, while a Scene is the container for all user interface elements associated with that Stage. The Stage provides the window boundaries, whereas the Scene holds the component hierarchy and manages user interface elements like buttons and text fields. Together, they define the layout and interaction elements visible to the user and function as the foundational building blocks of a JavaFX GUI application .

In JavaFX, alerts are managed using the Alert class. An instance of Alert is created by specifying the type, such as AlertType.INFORMATION. Developers set properties such as title and content text to convey messages, then invoke the show() method to display the dialog. This approach effectively communicates important information or feedback to users within applications, supporting interaction and user guidance during different app processes .

JavaFX's FXCollections class provides utility methods such as observableArrayList, which allow for the creation of ObservableLists. These lists are significant due to their ability to notify listeners about changes in real-time. When integrated with TableView, ObservableLists hold data items that are dynamically updated within the table, which streamlines data binding and ensures that the TableView displays up-to-date information. This capability is particularly useful for applications requiring dynamic data display and interaction .

JavaFX allows embedding custom styling through CSS (Cascading Style Sheets), offering developers a familiar syntax for defining visual aspects of a user interface. By associating CSS files like 'JMetroDarkTheme.css' or 'JMetroLightTheme.css' with JavaFX components, developers can apply styles globally or to specific UI elements, significantly extending the flexibility and appearance of applications. This approach enables easy theme modifications and visual customizations, enhancing user experience and UI design consistency .

JavaFX ensures real-time changes in data structures through its ObservableList interface, which notifies change listeners about updates, additions, or removals of items. This feature is combined with controls like TableView to dynamically reflect changes in data on the user interface without manual refresh. This real-time responsiveness is critical for creating interactive and fluid UIs, providing users with instant feedback and accurate data representation, thus enhancing the overall application experience .

In JavaFX, the MVC pattern separates concerns within an application into three interconnected components: Model, View, and Controller. The Model represents the logical structure of data, reflecting the application's domain logic. The View consists of the user interfaces and graphical elements users interact with. The Controller acts as an intermediary, managing input and updating both the View and Model accordingly. This separation is significant as it allows for modular design, making the application easier to maintain, extend, and test .

Vous aimerez peut-être aussi