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 :

Changer un composant après l'exécution de l'interface


Sujet :

JavaFX

  1. #1
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2021
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2021
    Messages : 11
    Points : 3
    Points
    3
    Par défaut Changer un composant après l'exécution de l'interface
    Bonjour,
    J'ai une classe gui qui affiche une interface qui contient un simple rectangles.
    Je veux trouver un moyens pour afficher cette interfaces à partir d'une classe extérieur et de changer la couleur de ce rectangles après l'exécution.

    S'ils vous plaît aidez moi, je vous remercie d'avance !!

  2. #2
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 840
    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 840
    Points : 22 854
    Points
    22 854
    Billets dans le blog
    51
    Par défaut
    Et si tu nous montrais ton code ?
    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
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2021
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2021
    Messages : 11
    Points : 3
    Points
    3
    Par défaut
    Citation Envoyé par bouye Voir le message
    Et si tu nous montrais ton code ?
    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
    package com.example.simpleproject;
     
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.layout.BorderPane;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.Rectangle;
    import javafx.stage.Stage;
     
    public class GUI extends Application {
     
        @Override
        public void start(Stage stage) throws Exception {
     
            Rectangle LED = new Rectangle();
            LED = new Rectangle();
            LED.setWidth(50);
            LED.setHeight(50);
            LED.setFill(Color.RED);
     
            BorderPane borderPane = new BorderPane(LED);
            Scene scene = new Scene(borderPane, 300, 300);
            stage.setTitle("Hello!");
            stage.setScene(scene);
            stage.show();
     
        }
        public void Lancer()
        {
            launch();
        }
    }
    C'est juste un code très simple une classe qui affiche son contenue et je vous l'afficher à partir d'une autre classe quelconque et modifier par exemple la couleur du rectangle (LED) après l'affichage de cette interface.

  4. #4
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 840
    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 840
    Points : 22 854
    Points
    22 854
    Billets dans le blog
    51
    Par défaut
    Par exemple :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     final var LED = new Rectangle();
    [...]
    var button = new Button("Click me!");
    button.setOnAction(event -> LED.setFill(Color.BLUE));
    borderPane.setBottom(button);
    PS: éviter les noms de variable tout en majuscule quand c'est pas des variables statiques.
    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

  5. #5
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2021
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2021
    Messages : 11
    Points : 3
    Points
    3
    Par défaut
    Bonjour,
    C'est ça le problème c'est que je veux faire ça sans l'utilisation des boutons just à l'intérieur du code

  6. #6
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 840
    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 840
    Points : 22 854
    Points
    22 854
    Billets dans le blog
    51
    Par défaut
    Et donc, fonctionnellement, qu'est ce qui est censer déclencher le changement de couleur ?
    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

  7. #7
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2021
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2021
    Messages : 11
    Points : 3
    Points
    3
    Par défaut
    Bonjour, c'est le changement de l'etat d'un thread quelconque d'un programme de l'utilisateur qu'on doit suivre son etat régulièrement

  8. #8
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 840
    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 840
    Points : 22 854
    Points
    22 854
    Billets dans le blog
    51
    Par défaut
    Dans l'autre topic, tu as un moniteur de thread dont la propriété value change de valeur au fil de l'exécution du thread observé. Il faut donc réagir à ces valeur via, par exemple, un ChangeListener. Avez-vous des cours sur ce genre de choses avant d'attaquer JavaFX ?
    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

  9. #9
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2021
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2021
    Messages : 11
    Points : 3
    Points
    3
    Par défaut
    Bonjour, non j'ai pas eu des cours de java just quelque tuto que j'ai regardé , c'est just un petit projet à faire et comme on a pas beaucoup de temps je suis obligé de chercher de l'aide

  10. #10
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 840
    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 840
    Points : 22 854
    Points
    22 854
    Billets dans le blog
    51
    Par défaut
    Un petit truc comme ça pourrait faire un bon début pour commencer :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    module test.threadmonitor {
        requires javafx.controls;
        requires javafx.graphics;
        exports test.threadmonitor;
    }
    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
    package test.threadmonitor;
     
    import javafx.concurrent.ScheduledService;
    import javafx.concurrent.Task;
    import javafx.util.Duration;
     
    import java.util.Objects;
     
    public final class ThreadMonitor extends ScheduledService<Thread.State> {
        private static final short REFRESH_RATE = 200;
     
        private Thread thread;
     
        public ThreadMonitor(final Thread thread) {
            Objects.requireNonNull(thread);
            this.thread = thread;
            setPeriod(Duration.millis(REFRESH_RATE));
        }
     
        private int iteration = 0;
     
        @Override
        protected Task<Thread.State> createTask() {
            return new Task<Thread.State>() {
                protected Thread.State call() {
                    System.out.printf("%d - alive: %b - state: %s\n", iteration++, thread.isAlive(), thread.getState());
                    final var state = thread.getState();
                    updateValue(state);
                    return state;
                }
            };
        }
    }
    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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    package test.threadmonitor;
     
    import javafx.application.Application;
    import javafx.beans.value.ChangeListener;
    import javafx.event.ActionEvent;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.ToolBar;
    import javafx.scene.layout.BorderPane;
    import javafx.scene.layout.StackPane;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.Circle;
    import javafx.scene.shape.Shape;
    import javafx.stage.Stage;
     
    import java.util.Optional;
    import java.util.function.Function;
     
    public final class Main extends Application {
        private Button button;
        private Shape led;
     
        @Override
        public void start(final Stage stage) throws Exception {
            button = new Button("Start");
            button.setOnAction(this::onButton);
            final var toolbar = new ToolBar();
            toolbar.getItems().setAll(button);
            led = new Circle(25, Color.TRANSPARENT);
            led.setStroke(Color.BLACK);
            final var container = new StackPane();
            container.getChildren().setAll(led);
            final var root = new BorderPane();
            root.setTop(toolbar);
            root.setCenter(container);
            final var scene = new Scene(root);
            stage.setTitle("Test");
            stage.setWidth(800);
            stage.setHeight(600);
            stage.setScene(scene);
            stage.show();
        }
     
        private ThreadMonitor threadMonitor;
     
        private void onButton(final ActionEvent event) {
            Optional.ofNullable(threadMonitor)
                    .ifPresent(ThreadMonitor::cancel);
            threadMonitor = null;
            button.setDisable(true);
            //
            final var thread = new Thread(() -> {
                System.out.println("Start thread.");
                try {
                    for (int i = 0; i < 2; i++) {
                        System.out.printf("Sleep %d.\n", i + 1);
                        Thread.sleep(5000);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("End thread.");
            });
            final ChangeListener<Thread.State> listener = (value, oldValue, newValue) -> {
                System.out.printf("State changed from %s to %s\n", oldValue, newValue);
                final var color = STATE_TO_COLOR_CONVERTER.apply(newValue);
                led.setFill(color);
                if (Thread.State.TERMINATED == newValue) {
                    threadMonitor.cancel();
                }
            };
            final var monitor = new ThreadMonitor(thread);
            monitor.setOnCancelled(anotherEvent -> {
                threadMonitor.lastValueProperty().removeListener(listener);
                threadMonitor = null;
                button.setDisable(false);
            });
            monitor.lastValueProperty().addListener(listener);
            monitor.start();
            threadMonitor = monitor;
            thread.start();
        }
     
        private static final Function<Thread.State, Color> STATE_TO_COLOR_CONVERTER = state -> Optional.ofNullable(state)
                .map(val -> switch (val) {
                    case NEW -> Color.PINK; // Wait to start.
                    case BLOCKED -> Color.RED; // Blocked by another thread.
                    case WAITING -> Color.PURPLE; // Wait for another thread.
                    case RUNNABLE -> Color.GREEN; // Compute.
                    case TERMINATED -> Color.BLACK; // End.
                    case TIMED_WAITING -> Color.BLUE; // Sleep.
                })
                .orElse(Color.TRANSPARENT);
    }
    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

  11. #11
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2021
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2021
    Messages : 11
    Points : 3
    Points
    3
    Par défaut
    Bonjour Monsieur,
    Merci c'est très gentil de votre part, j'essaierai de comprendre tout ça et de m'adapter avec mon sujet. Mercii !!

Discussions similaires

  1. faire disparaître la console après l'exécution d'un scr .bat
    Par Essilife dans le forum Autres Logiciels
    Réponses: 2
    Dernier message: 17/01/2006, 14h49
  2. Réponses: 7
    Dernier message: 24/10/2005, 23h10
  3. Réponses: 3
    Dernier message: 01/10/2005, 20h02
  4. [BorderLayout] Changer le composant
    Par calypso dans le forum Agents de placement/Fenêtres
    Réponses: 6
    Dernier message: 12/04/2005, 11h58
  5. redimentiondes composant a l'excution
    Par edam dans le forum Composants VCL
    Réponses: 3
    Dernier message: 18/10/2004, 15h13

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