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 :

Probleme sur JavaFx


Sujet :

JavaFX

  1. #1
    Candidat au Club
    Homme Profil pro
    Architecte logiciel
    Inscrit en
    Septembre 2014
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Congo-Kinshasa

    Informations professionnelles :
    Activité : Architecte logiciel
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Septembre 2014
    Messages : 5
    Points : 4
    Points
    4
    Par défaut Probleme sur JavaFx
    Bonsoir a tous,
    j'ai récemment commencer a programmer en java et je suis sur javaFx actuellement
    depuis hier j'essai de faire interagir un client et un serveur , dans la classe serveur j'ai crée un ServerSocket et je lai lance dans un nouveau thread mais quand je démarre le serveur , la fenêtre ne répond pas . Que doit je faire pour corrigé l'erreur , Merci d'avance
    voici le code du serveur :
    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
    package com.company;
     
    import javafx.application.Application;
    import javafx.application.Platform;
    import javafx.scene.Scene;
    import javafx.scene.control.*;
    import javafx.stage.Stage;
    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.io.IOException;
    import java.net.*;
    import java.util.Date;
     
    public class Server  extends Application{
     
        public static final int port = 13000;
     
        @Override
        public void start(Stage primaryStage) throws IOException {
            TextArea ta = new TextArea();
            Scene scene = new Scene(new ScrollPane(ta));
            primaryStage.setTitle("Serveur");
            primaryStage.setScene(scene);
            primaryStage.show();
     
     
            new Thread(()->{
                try {
                    ServerSocket server = new ServerSocket(port);
                    Platform.runLater(()->{
                        ta.appendText("server started at "+ new Date()+" \n");
                        try {
                            Socket socket = server.accept();
                            DataInputStream input = new DataInputStream(socket.getInputStream());
                            DataOutputStream output = new DataOutputStream(socket.getOutputStream());
                            while(true){
                                double raduis = input.readDouble();
                                double area = raduis*raduis*Math.PI;
                                output.writeDouble(area);
                                Platform.runLater(()-> {
                                    ta.appendText("raduis receive from client : "+raduis+"\n");
                                    ta.appendText("area send to the client "+ area+"\n");
                                });
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
     
                    });
     
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }

  2. #2
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 838
    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 838
    Points : 22 846
    Points
    22 846
    Billets dans le blog
    51
    Par défaut
    Bonjour,
    tu démarres un nouveau thread, certes, mais dedans au final tu lances ta boucle d'attente via Platform.runLater() donc cette boucle infinie s’exécute dans le JavaFX Application Thread, donc tu bloques tout, donc rien ne s'affiche, donc c'est normal CQFD.

    Accessoirement -> Tutoriel sur l'exécution d'une tâche de fond en JavaFX
    Mais tu peux bien sur conserver des threads basiques pour faire la même chose (faut juste éviter de lancer la boucle infinie comme tu l'as fait ici).
    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
    Architecte logiciel
    Inscrit en
    Septembre 2014
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Congo-Kinshasa

    Informations professionnelles :
    Activité : Architecte logiciel
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Septembre 2014
    Messages : 5
    Points : 4
    Points
    4
    Par défaut
    Merci pour la reponse

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

Discussions similaires

  1. [LG]Probleme sur l'identification de typage
    Par axelmeunier dans le forum Langage
    Réponses: 10
    Dernier message: 19/01/2004, 14h41
  2. Réponses: 3
    Dernier message: 07/04/2003, 21h06
  3. Probleme sur le Fields des fichiers Xmlgram
    Par Sandrine75 dans le forum XMLRAD
    Réponses: 4
    Dernier message: 20/03/2003, 18h09
  4. Probleme sur un AppendChild
    Par Toxine77 dans le forum XMLRAD
    Réponses: 3
    Dernier message: 14/03/2003, 19h25
  5. Probleme sur les chaines de caractere
    Par scorpiwolf dans le forum C
    Réponses: 8
    Dernier message: 06/05/2002, 20h01

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