kpidiba / JAVAFX

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JAVAFX

DESCRIPTION

JavaFX est un framework et une bibliothèque d'interface utilisateur issue du projet OpenJFX, qui permet aux développeurs Java de créer une interface graphique pour des applications de bureau, des applications internet riches et des applications smartphones et tablettes tactiles.

Créé à l'origine par Sun MicroSystems, puis développé par Oracle après son rachat et ce, jusqu'à la version 11 du JDK, c'est depuis lors à la communauté OpenJFX que revient la poursuite de son développement1.

Cette bibliothèque a été conçue pour remplacer Swing et AWT, qui ont été développés à partir de la fin des années 90, pour pallier les défauts de ces derniers et fournir de nouvelles fonctionnalités (dont le support des écrans tactiles).

Le cycle de sortie d'une nouvelle version de JavaFX correspond à celui de Java, soit tous les 6 mois.

RESSOURCES

ICONS

Scene Builder: l'outil de conception d'interfaces

Scene Builder est un outil interactif de conception d'interface graphique pour JavaFX. Il permet de créer des interfaces utilisateurs rapidement et sans avoir besoin de coder: il en résulte des fichiers au format FXML qui sont ensuite chargés par le programme pour afficher une interface graphique à ses utilisateurs.

Développé initialement par Oracle et sous le nom JavaFX Scene Builder5, son code source a été publié en open source à partir de sa version 2.06.

Depuis, le logiciel est principalement développé et soutenu par la société Gluon7.

Manually Adding External Dependencies Scene Builder

If you are unable to use Maven to manage dependencies in your Java project and need to add JAR files manually, follow these steps:

  1. Download the JAR File: Obtain the JAR file for the desired dependency, such as com.ultramixer:laddafx:0.2.1, from a repository like Maven Central or the project's website.

  2. Add JAR to Your Project: Place the downloaded JAR file in a directory within your project, such as lib/.

  3. Add JAR to IntelliJ IDEA:

    • Click on the parameter icon located on the right of the Library section.
    • In the search field, type "JAR/FXML Manager" and select it.
    • Follow the prompts to locate and add the JAR file you downloaded to your project.

COMPOSANTS

JavaFX est composé des 7 modules suivants:

  • javafx.base: Définit l'API de base
  • javafx.controls: Définit la majorité des composants graphiques de l'API
  • javafx.fxml: Définit l'API relative au langage FXML qui permet de décrire une interface utilisateur d'une manière alternative à l'écriture de lignes de code
  • javafx.graphics: Définit l'API relative aux conteneurs, animations, effets visuels, formes 2D et 3D, images, impression, fenêtres, événements, robots, au support du CSS et à l'application
  • javafx.media: Définit l'API dédié à la lecture de contenu audio et vidéo
  • javafx.swing: Définit l'API qui fournit le support d’interopérabilité entre JavaFX et Swing
  • javafx.web: Définit l'API dédié à l'affichage de contenu web (notamment un éditeur HTML et un moteur de rendu de pages web basé sur WebKit)

INSTALLATION

To properly set up your JavaFX project environment, follow these steps:

  1. Install Necessary Extensions:

    • Ensure you have the following extensions installed in your development environment:
      • JavaFX Support
      • FXML Viewer
      • Java Extension Pack
  2. Install Scene Builder:

  3. Download JDK and SDK:

    • Download the JavaFX SDK for x64 architecture from Gluon's website.
    • Extract the downloaded SDK to C:/ and select the second folder during extraction.
  4. Create Java Project:

    • Start by creating a new Java project without any build tools.
  5. Configure Project Settings:

    • Navigate to the main directory of your Java project, and it will appear in the sidebar or at the bottom of the IDE.
    • Click on "References Libraries" and add all the necessary SDK libraries for JavaFX.
  6. Add Run Configuration:

    • Click on "Run" and then "Add Configuration" to configure the run settings.
  7. Set VM Options:

    • Go to the documentation for javax in NetBeans and search for VM options.
    • Copy and paste the following VM options
"vmArgs": "--module-path \"C:/javafx-sdk-20.0.1/lib\" --add-modules javafx.controls,javafx.fxml"

Source Code:

  • Use the provided Java source code to initialize a basic JavaFX application. Ensure that you replace the existing code with the provided one.
  • This code sets up a simple "Hello World" application using JavaFX.
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class App extends Application {
    @Override
    public void start(Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
       btn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent arg0) {
                System.out.println("Hello World!");
            }

        });

        StackPane root = new StackPane();
        root.getChildren().add(btn);

  /*
  Parent root = FXMLLoader.load(getClass().getResource("MainScene.fxml"));
  Scene scene = new Scene(root);
  */

  Scene scene = new Scene(root, 300, 250);

  primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

 public static void main(String[] args) {
        launch(args);
    }
}

LAUNCH WITH SDK

  • Just Copy the sdk content to new folder

  • Create Class with all javafx code

  • create Launcher with will configuration data

Create Scene and Controller:

  • Create a scene and add it to the source code as per your application requirements.
  • Navigate to View and select Show Sample Controller Skeleton.
  • Add the controller class to the view to manage the application logic.

GENERATE JAR VS CODE

  • CLIQUER SUR EXPORT JAR FILE

  • COMMAND TO LAUNCH IT

JAVA -jar --module-path "/path/to/JavaFX/lib" --add-modules=javafx.controls jar_file_name.jar 

About


Languages

Language:Java 93.0%Language:CSS 7.0%