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

Agents de placement/Fenêtres Java Discussion :

Lancement d'une application après login


Sujet :

Agents de placement/Fenêtres Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de richard_sraing
    Homme Profil pro
    Responsable de service informatique
    Inscrit en
    Avril 2005
    Messages
    483
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Responsable de service informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Avril 2005
    Messages : 483
    Par défaut Lancement d'une application après login
    Bonjour à tous,

    Alors voilà, afin de réaliser une application de manière la plus propre possible, je souhaiterai récolter vos avis sur la manière de procéder.

    Je développe actuellement une application permettant une gestion de données. Pour accéder à l'application, je souhaite que l'utilisateur commence par s'authentifier.
    Je souhaite qu'une fenêtre permettant la saisie du username et du password apparaisse avant la fenêtre d'application proprement dites.

    Voici donc le code contenant le main de mon application côté client :
    Code JAVA : 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
    package agmdclient;
    import Communications.cComAuthentification;
    import GUI.jfLogin;
    import javax.swing.JFrame;
    /**
     * @version 0.0.1
     * @author raphael threis
     */
    public class AgmdClient {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
     
            cComAuthentification oComAuth = new cComAuthentification();
     
            jfLogin jfl = new jfLogin(oComAuth);
            jfl.setTitle("Connexion à AGMD");
            jfl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            jfl.setVisible(true);
     
            System.out.println("Username: "+oComAuth.getUsername()+" Mot de passe: "+oComAuth.getPassword());
     
        }
    }
    Et le code de ma Frame pour le login
    Code JAVA : 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
    package GUI;
    import Communications.cComAuthentification;
     
    /**
     * @version 0.0.1
     * @author raphael threis
     */
    public class jfLogin extends javax.swing.JFrame {
     
        cComAuthentification oComAuth;
        /**
         * Creates new form jfLogin
         */
        public jfLogin(cComAuthentification _value) {
            oComAuth = _value;
            initComponents();
        }
        public jfLogin() {
            initComponents();
        }
     
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
        // tout le code d'initialisation de la fenêtre
        }// </editor-fold>
     
        private void jbAnnulerActionPerformed(java.awt.event.ActionEvent evt) {
            this.dispose(); // je souhaite terminer l'application (autre solution préconisée ?)
        }
     
        private void jbConnecterActionPerformed(java.awt.event.ActionEvent evt) {
            oComAuth.setUsername(this.jtfUsername.getText());
            oComAuth.setPassword(this.jpfPassword.getPassword().toString());
            System.out.println("Username: "+oComAuth.getUsername()+" Mot de passe: "+oComAuth.getPassword());
     
     
     
            //this.dispose();
        }
     
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /*
             * Set the Nimbus look and feel
             */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /*
             * If Nimbus (introduced in Java SE 6) is not available, stay with the
             * default look and feel. For details see
             * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(jfLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(jfLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(jfLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(jfLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
     
            /*
             * Create and display the form
             */
            java.awt.EventQueue.invokeLater(new Runnable() {
     
                public void run() {
                    new jfLogin().setVisible(true);
                }
            });
        }
        // Variables declaration - do not modify
        private javax.swing.JButton jbAnnuler;
        private javax.swing.JButton jbConnecter;
        private javax.swing.JLabel jlPassword;
        private javax.swing.JLabel jlUsername;
        private javax.swing.JLabel jlWelcome;
        private javax.swing.JPasswordField jpfPassword;
        private javax.swing.JTextField jtfUsername;
        // End of variables declaration
    }

    Alors, ce que je souhaite savoir, c'est comment mettre en place l'authentification auprès du serveur ?
    J'ai pensé à plusieurs solution, mais je ne sais pas si une des solutions trouvées est la meilleure, ou alors si elles sont toutes pourries.
    1. Dans ma jFrame jfLogin, j'intègre tout le code de connexion au serveur, demande d'authentification, de vérification de réponse, ... [mon avis -> pas bon, car il faut garder le moins possible de traitement données dans l'interface afin de ne pas avoir d'effet de freeze]
    2. La fenêtre de connexion lance un thread, qui établit la connexion avec le serveur, demande l'authentification, analyse la réponse, et retourne une valeur à la frame. [mon avis -> semble plus logique, et permettrait de réaliser une "animation" de tâche en cours sur la frame]
    3. Retourner les informations d'authentification vers le "main" de l'application, fermer la boite de dialogue. Etablir la connexion avec le serveur dans le main, demander l'authentification, analyser la réponse, si OK, on affiche la fenêtre principale de l'application, dans le cas contraire, on réaffiche la frame de login. [mon avis -> solution tirée par les cheveux, fermer une frame pour potentiellement la rouvrir 5 secondes plus tard, est un non sens].

    Pour les solutions 1 et 2, je ne sais pas contre pas comment faire, pour dire à mon main d'attendre la réponse de la frame de login. J'ai vu sur certains sites / forums qu'il fallait utiliser les events, mais je ne comprend pas comment les mettre en place. Est ce que je dois créer un event propre à mes besoins (par exemple un eventLogged ?) ou alors utiliser une event existant ?

    En vous remerciant pour toutes les pistes, informations, remarques et avis qu'il vous sera possible de me donnner, je vous souhaite à tous une bonne journée.

  2. #2
    Membre éclairé Avatar de richard_sraing
    Homme Profil pro
    Responsable de service informatique
    Inscrit en
    Avril 2005
    Messages
    483
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Responsable de service informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Avril 2005
    Messages : 483
    Par défaut
    Après m'être quelque peu creusé la nènette, j'ai encore trouvé une autre solution, mais ne sais pas trop comment l'appliquer.

    Code JAVA : 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
    package agmdclient;
    import Communications.cComAuthentification;
    import GUI.jfLogin;
    import java.io.IOException;
    import java.io.PipedInputStream;
    import java.io.PipedOutputStream;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JFrame;
    /**
     * @version 0.0.1
     * @author raphael threis
     */
    public class AgmdClient {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
     
            cComAuthentification oComAuth = new cComAuthentification();
            cThCommunication oThComm = new cThCommunication();
            ExecutorService esThComm;
            PipedOutputStream pos; // lit la data
            PipedInputStream pis; // écrit la data
     
            esThComm = Executors.newSingleThreadExecutor();
     
            esThComm.submit(oThComm);
            try{
                pos = new PipedOutputStream();
                pis = new PipedInputStream(pos);
            }
            catch (IOException ioe){
                System.out.println("Erreur lors de la création du pipe de communication entre X et Thread de Communication : "+ioe.getMessage());
                System.exit(-1);
            }
     
            jfLogin jfl = new jfLogin(oComAuth);
            jfl.setTitle("Connexion à AGMD");
            jfl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            jfl.setVisible(true);
            try {
                jfl.wait();
            } catch (InterruptedException ex) {
                Logger.getLogger(AgmdClient.class.getName()).log(Level.SEVERE, null, ex);
            }
     
            System.out.println("Username: "+oComAuth.getUsername()+" Mot de passe: "+oComAuth.getPassword());
     
        }
    }
    En fait, je pense mettre en place un wait(); sur ma jframe permettant le login.

    En dans le l'évènement de clic sur Connect de ma JFrame
    Code JAVA : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    private void jbConnecterActionPerformed(java.awt.event.ActionEvent evt) {
            oComAuth.setUsername(this.jtfUsername.getText());
            oComAuth.setPassword(this.jpfPassword.getPassword().toString());
            System.out.println("In JFrame Username: "+oComAuth.getUsername()+" Mot de passe: "+oComAuth.getPassword());
            notify();
            this.dispose();
        }

    Cela parait très joli, et pourtant, cela ne fonctionne pas. J'obtiens bien que le main attentds, mais il me fait une série d'erreur que voici :
    run:
    Exception in thread "main" java.lang.IllegalMonitorStateException
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:503)
    at agmdclient.AgmdClient.main(AgmdClient.java:46)
    In JFrame Username: test Mot de passe: [C@1f2af1c
    Exception in thread "AWT-EventQueue-0" java.lang.IllegalMonitorStateException
    at java.lang.Object.notify(Native Method)
    at GUI.jfLogin.jbConnecterActionPerformed(jfLogin.java:122)
    at GUI.jfLogin.access$000(jfLogin.java:8)
    at GUI.jfLogin$1.actionPerformed(jfLogin.java:55)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6505)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    at java.awt.Component.processEvent(Component.java:6270)
    at java.awt.Container.processEvent(Container.java:2229)
    at java.awt.Component.dispatchEventImpl(Component.java:4861)
    at java.awt.Container.dispatchEventImpl(Container.java:2287)
    at java.awt.Component.dispatchEvent(Component.java:4687)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.java:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2719)
    at java.awt.Component.dispatchEvent(Component.java:4687)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:703)
    at java.awt.EventQueue.access$000(EventQueue.java:102)
    at java.awt.EventQueue$3.run(EventQueue.java:662)
    at java.awt.EventQueue$3.run(EventQueue.java:660)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:676)
    at java.awt.EventQueue$4.run(EventQueue.java:674)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:673)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
    Toutes idées, remarques, et autres sont toujours les bienvenues.

  3. #3
    Membre éclairé Avatar de richard_sraing
    Homme Profil pro
    Responsable de service informatique
    Inscrit en
    Avril 2005
    Messages
    483
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Responsable de service informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Avril 2005
    Messages : 483
    Par défaut Mouhahaha, le roi des porcs du codage
    J'ai une solution à la 6.4.2:

    Code JAVA : Sélectionner tout - Visualiser dans une fenêtre à part
    while(maFrame.isVisible()){}

    Quelqu'un aurait-il une solution beaucoup plus propre à proposer s'il vous plait ?

  4. #4
    Membre éclairé Avatar de richard_sraing
    Homme Profil pro
    Responsable de service informatique
    Inscrit en
    Avril 2005
    Messages
    483
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Responsable de service informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Avril 2005
    Messages : 483
    Par défaut
    Bon, on oublie, je vais faire autrement.

    Je lance ma fenêtre principale à partir de ma fenêtre de login, et je laisserai le thread main dans le vide.

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

Discussions similaires

  1. Lancement d'une application au login sous Redhat
    Par pjquilichini dans le forum Administration système
    Réponses: 1
    Dernier message: 30/03/2006, 16h51
  2. [Exécutable]lancement d'une application
    Par jesus144 dans le forum Général Java
    Réponses: 9
    Dernier message: 08/06/2005, 10h08
  3. [Plugin][MyEclipse]Lancement d'une application J2EE
    Par ujoodha dans le forum Eclipse Java
    Réponses: 3
    Dernier message: 20/04/2005, 15h48
  4. Détecter le lancement d'une application
    Par Neilos dans le forum Windows
    Réponses: 8
    Dernier message: 22/11/2004, 12h32
  5. Lancement d'une application en local (!)
    Par Fifoun dans le forum MFC
    Réponses: 5
    Dernier message: 12/06/2004, 17h09

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