IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaFX Discussion :

lancement d'une interface FX sans la méthode main


Sujet :

JavaFX

  1. #1
    Membre à l'essai
    Inscrit en
    Novembre 2012
    Messages
    33
    Détails du profil
    Informations forums :
    Inscription : Novembre 2012
    Messages : 33
    Points : 20
    Points
    20
    Par défaut lancement d'une interface FX sans la méthode main
    pour la réalisation d'un programme Agent avec JADE, j'ai utilisé l'interface graphique javaFX, et à partir d'un agent je lance l'interface avec ce code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    interface = new Interface();
     
            Interface.launch(Interface.class);
            Interface.setAgentInterface(this);
     
            // le reste de code
    l'interface s'affiche et fonctionne très bien, mais le reste de code après le lancement de l'interface ne s’exécute pas, et l'objet passé en paramètre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Interface.setAgentInterface(this);
    prend la valeur null.

    j'ai le même code avec une interface swing, et il marche sans aucun problème.

    Merci d'avance pour votre aide.

  2. #2
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 845
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 845
    Points : 22 859
    Points
    22 859
    Billets dans le blog
    51
    Par défaut
    Cela semble indiquer que la méthode launch() est une méthode bloquante qui ne retournera que quand l'interface sera fermée, ce qui est d'ailleurs indiqué dans la doc.

    Citation Envoyé par https://docs.oracle.com/javase/8/javafx/api/javafx/application/Application.html#launch-java.lang.Class-java.lang.String...-
    The launch method does not return until the application has exited, either via a call to Platform.exit or all of the application windows have been closed.
    De plus, tu crée ici deux instances de l'interface :
    1. La première en faisant new.
    2. La second en invoquant launch().



    Voit si tu peux adapter ceci a ton framework :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    package fxlaunch;
     
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javafx.application.Platform;
    import javafx.embed.swing.JFXPanel;
    import javafx.stage.Stage;
    public class Main {
     
        public static void main(String... args) {
            try {
                // Seule manière publique actuelle de lancer les runtimes a la main.
                // Une autre manière de faire sera disponible dans le JDK 9.
                new JFXPanel();
                //
                final AppFX app = new AppFX();
                app.init();
                Platform.runLater(() -> {
                    try {
                        final Stage stage = new Stage();
                        app.start(stage);
                        app.setValue(10);
                    } catch (Exception ex) {
                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                    }
                });
            } catch (Exception ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    package fxlaunch;
     
    import javafx.application.Application;
    import javafx.beans.binding.Bindings;
    import javafx.beans.property.IntegerProperty;
    import javafx.beans.property.SimpleIntegerProperty;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
     
    public final class AppFX extends Application {
     
        @Override
        public void start(Stage primaryStage) throws Exception {
            final Label label = new Label();
            label.textProperty().bind(Bindings.convert(valueProperty()));
            final StackPane root = new StackPane(label);
            final Scene scene = new Scene(root, 300, 300);
            primaryStage.setTitle("AppFX");
            primaryStage.setScene(scene);
            primaryStage.show();
        }
     
        private final IntegerProperty value = new SimpleIntegerProperty(this, "value", -1);
     
        public final void setValue(final int value) {
            this.value.set(value);
        }
     
        public final int getValue() {
            return value.get();
        }
     
        public IntegerProperty valueProperty() {
            return value;
        }
    }
    Merci de penser au tag quand une réponse a été apportée à votre question. Aucune réponse ne sera donnée à des messages privés portant sur des questions d'ordre technique. Les forums sont là pour que vous y postiez publiquement vos problèmes.

    suivez mon blog sur Développez.

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning. ~ Rich Cook

  3. #3
    Membre à l'essai
    Inscrit en
    Novembre 2012
    Messages
    33
    Détails du profil
    Informations forums :
    Inscription : Novembre 2012
    Messages : 33
    Points : 20
    Points
    20
    Par défaut
    Merci beaucoup monsieur bouye, ça marche très très bien

  4. #4
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 845
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 845
    Points : 22 859
    Points
    22 859
    Billets dans le blog
    51
    Par défaut
    De rien.
    Essaie de voir si tu peux ajouter ça pour avoir le cycle de vie complet de l'application (init(), start(), stop()) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    final Stage stage = new Stage()
    stage.addEventFilter(WindowEvent.WINDOW_CLOSE_REQUEST, windowEvent -> {
        try {
            app.stop();
        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    });
    [...]
    Merci de penser au tag quand une réponse a été apportée à votre question. Aucune réponse ne sera donnée à des messages privés portant sur des questions d'ordre technique. Les forums sont là pour que vous y postiez publiquement vos problèmes.

    suivez mon blog sur Développez.

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning. ~ Rich Cook

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 8
    Dernier message: 02/04/2015, 14h51
  2. lancer une application javaFX sans la méthode main
    Par win_ubuntu dans le forum JavaFX
    Réponses: 1
    Dernier message: 12/07/2014, 01h24
  3. Passage d'une interface en paramètre de méthode COM
    Par sylvain.cool dans le forum C++
    Réponses: 11
    Dernier message: 18/04/2008, 14h15
  4. [Débutant] Réinitialiser une interface graphique sans en sortir
    Par Alucard9800XT dans le forum Interfaces Graphiques
    Réponses: 9
    Dernier message: 23/04/2007, 16h32
  5. Réponses: 4
    Dernier message: 02/05/2006, 12h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo