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

Interfaces Graphiques en Java Discussion :

Demande d'information en Java


Sujet :

Interfaces Graphiques en Java

  1. #1
    Membre du Club
    Inscrit en
    Octobre 2011
    Messages
    119
    Détails du profil
    Informations forums :
    Inscription : Octobre 2011
    Messages : 119
    Points : 42
    Points
    42
    Par défaut Demande d'information en Java
    Bonjour,

    Je suis débutante en Java.

    J'ai un problème avec un JFrame qui contient deux JFormattedText, l'un pour nbrePage et l'autre pour la proportion de partage. J'ai fait une fonction get pour récupérer le nombre de pages car j'ai besoin de lui dans un autre JFrame.

    Le problème est que si j'appelle la fonction get dans JFrame qui contient le JFormattedText du nombre de page, la fonction get renvoie la valeur saisie
    mais si je l'appelle à partir de la deuxième JFrame, un message d'erreur s'affiche.

    Je convertis la valeur récupérée de la JFormattedText en integer avec parseInt.

    Quelqu'un saurait-il me guider un peu ?

    Merci d'avance pour votre aide.

  2. #2
    Membre confirmé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Points : 532
    Points
    532
    Par défaut
    Tu peux mettre du code ?

  3. #3
    Membre du Club
    Inscrit en
    Octobre 2011
    Messages
    119
    Détails du profil
    Informations forums :
    Inscription : Octobre 2011
    Messages : 119
    Points : 42
    Points
    42
    Par défaut
    voici le code de la première JFrame (FenetreReseauSocial)
    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
    95
    96
    97
    98
    99
    100
    101
    102
    package reseau;
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.IOException;
     
    import java.text.NumberFormat;
     
     
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JFormattedTextField; 
     
    public class FenetreReseauSocial extends JFrame {
     
            /**
         * 
         */
        private static final long serialVersionUID = 1L;
            private JPanel container = new JPanel();
            private JFormattedTextField nbrePageFacebook = new JFormattedTextField(NumberFormat.getIntegerInstance());
            private JFormattedTextField ProportionPartage = new JFormattedTextField(NumberFormat.getIntegerInstance());
     
            private JLabel label1 = new JLabel("Nombre de Page Facebook");
            private JLabel label2 = new JLabel("        Proportion de Partage");
            private JButton b = new JButton ("Appliquer");
     
     
     
            public FenetreReseauSocial(){
     
            this.setTitle("Paramètre du Réseau Social");
            this.setSize(400, 200);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setLocationRelativeTo(null);
     
            container.setBackground(Color.white);
            container.setLayout(new BorderLayout());
     
            JPanel top = new JPanel();
     
            Font police = new Font("Arial", Font.BOLD, 14);
            nbrePageFacebook.setFont(police);
            ProportionPartage.setFont(police);
            nbrePageFacebook.setPreferredSize(new Dimension(150, 30));
            ProportionPartage.setPreferredSize(new Dimension(150,30));
            nbrePageFacebook.setForeground(Color.BLUE);
            ProportionPartage.setForeground(Color.BLUE);
            b.addActionListener(new BoutonListener());
            top.add(label1);
            top.add(nbrePageFacebook);
            top.add(label2);
            top.add(ProportionPartage);
     
            top.add(b);
     
            this.setContentPane(top);
            this.setVisible(true);            
            }
           public JFormattedTextField getNbrePageFacebookString(){
                return nbrePageFacebook;
            }
            public Integer getNbrePageFacebookInt(){
                String nbrePageFacebookString = getNbrePageFacebookString().getText();
                 Integer nbrePageFacebookInt=Integer.parseInt(nbrePageFacebookString);
                 return nbrePageFacebookInt;
            } // ceci la fonction get qui permet de récupérer nbrePageFacebookInt
     
            public JFormattedTextField getProportionPartageString(){
                return ProportionPartage;
     
            }
            public int getProportionPartageInt(){
                String proportionPartageString = getProportionPartageString().getText();
                 int ProportionPartageInt = Integer.parseInt(proportionPartageString);
                return ProportionPartageInt;
            }
            class BoutonListener implements ActionListener{
     
                public void actionPerformed(ActionEvent e) {
     
                        System.out.println("Nbre de Pages Facebook: " + nbrePageFacebook.getText());
                        System.out.println("Proportion de Partage: " + ProportionPartage.getText());
                        int x=getNbrePageFacebookInt();
                        System.out.println(x);// elle renvoie la bonne valeur
     
                        setVisible(false);
                        FenetrePageFacebook fn1=new FenetrePageFacebook();
                      fn1.setVisible(true);
                }
            }
            public static void main(String[] args) throws IOException {
     
            }
     
    }
    et ceci le code de la deuxième JFrame (FenetrePageFacebook)
    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
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    package reseau;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.io.IOException;
    import java.text.NumberFormat;
    import java.util.ArrayList;
     
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFormattedTextField;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
     
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
     
    public class FenetrePageFacebook extends JFrame {
     
            /**
         * 
         */
        private static final long serialVersionUID = 1L;
            private JPanel container = new JPanel();
            private JTextField infoAuteur = new JTextField();
            private JFormattedTextField nbreAmis = new JFormattedTextField(NumberFormat.getIntegerInstance());
     
            private JComboBox listePolitiquePartage = new JComboBox();
            private JLabel label1 = new JLabel("Politique De Partage");
            private JComboBox listeFrequencePartage=new JComboBox();
            private JLabel label2= new JLabel("Fréquence De Partage");
            private JLabel label3= new JLabel("                Info Auteur  :");
            private JLabel label4= new JLabel("               Nbre d'Amis  :");
            private JButton b = new JButton ("Créer");
     
            ArrayList<PageFacebook> pages=new ArrayList<PageFacebook>();
            FenetreReseauSocial fn;
     
            public FenetrePageFacebook(){
                String[] tab1 = {"Public", "Amis et leurs Amis", "Amis Seulement", "Personnaliser"};
     
     
                listePolitiquePartage = new JComboBox(tab1);
    String[] tab2 = {"Fréquence De Partage Elevée", "Fréquence De Partage Moyenne", "Fréquence De Partage Faible"};
     
     
                listeFrequencePartage = new JComboBox(tab2);
     
            this.setTitle("Animation");
            this.setSize(400, 300);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setLocationRelativeTo(null);
     
            container.setBackground(Color.white);
            container.setLayout(new BorderLayout());
     
            listePolitiquePartage.setPreferredSize(new Dimension(150,30));
     
            listeFrequencePartage.setPreferredSize(new Dimension(200,30));
     
            infoAuteur.setPreferredSize(new Dimension(150, 30));
            nbreAmis.setPreferredSize(new Dimension(150,30));
            JPanel top = new JPanel();
     
            b.addActionListener(new BoutonListener());
     
            top.add(label3);
            top.add(infoAuteur);
     
            top.add(label4);
            top.add(nbreAmis);
     
            top.add(label1);
            top.add(listePolitiquePartage);
     
            top.add(label2);
            top.add(listeFrequencePartage);
     
            top.add(b);
            listePolitiquePartage.addItemListener(new ItemState());
            listePolitiquePartage.addActionListener(new ItemAction());
            listeFrequencePartage.addItemListener(new ItemState());
            listeFrequencePartage.addActionListener(new ItemAction());
     
            container.add(top);
            this.setContentPane(container);
            this.setVisible(false);
            }
            public JTextField getInfoAuteur(){
                return infoAuteur;
            }
     
            public JFormattedTextField getNbreAmis(){
                return nbreAmis;
            }
             public class ItemState implements ItemListener {
     
                 @Override
                 public void itemStateChanged(ItemEvent e) {
                     // TODO Auto-generated method stub
     
     
     
                 }
     
             }
             class ItemAction implements ActionListener{
     
                 public void actionPerformed(ActionEvent e) {
     
     
                 }               
         }
     
    public void getNombrepage(){
     
        String nbrePageFacebookString = fn.getNbrePageFacebookString().getText();
            Integer nbrePageFacebookInt=Integer.parseInt(nbrePageFacebookString);
    System.out.println(nbrePageFacebookInt);
    }
     
             public String getInfoAuteurString(){
                 String infoAuteurString = getInfoAuteur().getText();
                 return infoAuteurString;
             }
             public int getNbreAmisInt(){
                 String nbreAmisString = getNbreAmis().getText();
                    int nbreAmisInt = Integer.parseInt(nbreAmisString);
     
                    return nbreAmisInt;
     
             }
             public String getPolitiquePartage(){
                 String politiquePartageSelectionne= (String) listePolitiquePartage.getSelectedItem();
                    return politiquePartageSelectionne;
             }
             public String getFrequencePartage(){
                 String frequencePartageSelectionne=(String) listeFrequencePartage.getSelectedItem();
                    return frequencePartageSelectionne;
             }
     
             public int getNbre(){
                 FenetreReseauSocial fn = new FenetreReseauSocial();
                JFormattedTextField nbre= fn.getNbrePageFacebookString();
                String nbrePageFacebookString = nbre.getText();
                 Integer nbrePageFacebookInt=Integer.parseInt(nbrePageFacebookString);
                 return nbrePageFacebookInt;
     
             }// à ce niveau j'appelle la fonction get mais un message d'erreur qui s'affiche Exception in thread "main" java.lang.NullPointerException
        at reseau.FenetrePageFacebook.getNombrepage(FenetrePageFacebook.java:123)
        at reseau.principal.main(principal.java:25)
     
            class BoutonListener implements ActionListener{
     
              public void actionPerformed(ActionEvent e) {
     
                  PageFacebook nouvellepage= new PageFacebook();
                  nouvellepage.IdPage=1;
                  nouvellepage.InfoAuteur=getInfoAuteurString();
                  nouvellepage.NbAmis=getNbreAmisInt();
                  nouvellepage.PolitiquePartage=getPolitiquePartage();
                  nouvellepage.FrequencePartage=getFrequencePartage();
                  pages.add(nouvellepage);
                  System.out.println(pages.size());
                  System.out.println(pages.get(0).IdPage);
                  System.out.println(pages.get(0).InfoAuteur);
                  System.out.println(pages.get(0).NbAmis);
                  System.out.println(pages.get(0).PolitiquePartage);
                  System.out.println(pages.get(0).FrequencePartage);
              }
            }
     
        public static void main(String[] args) throws IOException {
            // TODO Auto-generated method stub
        }
    }

  4. #4
    Membre confirmé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Points : 532
    Points
    532
    Par défaut
    Est ce que getNombre est appelé avant getNombrePages ?
    Ta variable fn est créé dans la méthode getNombre, et tu en as besoin dans getNombrePages. La stackeTrace que tu envoies est incomplète où bien pas à l'endroit que tu indiques. Tu dis survenir dans la méthode getNombre mais la stackTrace dit getNbrePage

  5. #5
    Membre du Club
    Inscrit en
    Octobre 2011
    Messages
    119
    Détails du profil
    Informations forums :
    Inscription : Octobre 2011
    Messages : 119
    Points : 42
    Points
    42
    Par défaut
    en fait normalement les deux fonctions font la meme chose, en plus la variable fn est déclaré avec les attributs de la classe FenetrePageFacebook. et les deux classes sont appelés à partir de la classe principal.
    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
    package reseau;
     
    import java.io.IOException;
     
        public class principal{
     
        /**
         * @param args
         * @throws IOException 
         */
        public static void main(String[] args) throws IOException {
            FenetreReseauSocial fn= new FenetreReseauSocial();
            FenetrePageFacebook fn1=new FenetrePageFacebook();
     
            fn1.getNombrepage();
    }
        }
    en exécutant ce code ce message d'erreur s'affiche
    Exception in thread "main" java.lang.NullPointerException
    at reseau.FenetrePageFacebook.getNombrepage(FenetrePageFacebook.java:123)
    at reseau.principal.main(principal.java:25)

  6. #6
    Membre confirmé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Points : 532
    Points
    532
    Par défaut
    fn est déclaré en tant qu'attibut de la classe mais sa valeur vaut "null".
    A la ligne 123, tu fais fn.getNbrePageFacebookString

    Or fn est déclaré, mais pas contruit. Il faut avant faire

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    fn = new new FenetreReseauSocial();
    dans la classe FenetrePageFacebook

    Et ça, tu le fais bien dans getNombrepage()

  7. #7
    Membre du Club
    Inscrit en
    Octobre 2011
    Messages
    119
    Détails du profil
    Informations forums :
    Inscription : Octobre 2011
    Messages : 119
    Points : 42
    Points
    42
    Par défaut
    merci j'ai fait comme vous m'avez dit alors le message suivant s'affiche
    Exception in thread "main" java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at reseau.FenetrePageFacebook.getNombrepage(FenetrePageFacebook.java:126)
    at reseau.principal.main(principal.java:25)

  8. #8
    Membre confirmé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Points : 532
    Points
    532
    Par défaut
    Dans getNombrePageFacebook, vous avez l'instruction
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Integer.parseInt(nbrePageFacebookString);
    Cette méthode prend une string pour la transformer en entier. Or, la valeur passée est une chaine vide (car le JFormattedTextField est vide je pense). La string "" lève une exception. Avant d'appeler cette méthode, testez la valeur de nbrePageFacebookString avant l'instruction afin de ne pas l'appeler si la chaine est vide

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    if (!nbrePageFacebookString.equals("")) {
       Integer.parseInt(nbrePageFacebookString);
    }

  9. #9
    Membre du Club
    Inscrit en
    Octobre 2011
    Messages
    119
    Détails du profil
    Informations forums :
    Inscription : Octobre 2011
    Messages : 119
    Points : 42
    Points
    42
    Par défaut
    mais en principe la chaine n'est pas vide le JFormattedText normalement contient le nombre de page Facebook et ce nombre que je veux le récupérer de la frame FenetreReseauSocial à partir de la FenetrePageFacebook.
    en plus si j'apelle la fonction get dans la classe FenetreReseauSocial elle renvoie la bonne valeur mais en appelant la fonction à partir de la FenetrePageFacebook elle me donne rien.

  10. #10
    Membre confirmé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Points : 532
    Points
    532
    Par défaut
    Clairement vu ce que la stackTrace vous dit, la valeur vaut ""

    Si vous affichez le contenu de la variable par la console, vous avez quoi ?
    Sinon, si vous transformez la string en entier dans la classe qui fonctionne et appeler la méthode qui envoie un int depuis l'autre classe ça donne quoi ?

    Un conseil, indentez mieux votre code, c'est difficile à suivre

  11. #11
    Membre du Club
    Inscrit en
    Octobre 2011
    Messages
    119
    Détails du profil
    Informations forums :
    Inscription : Octobre 2011
    Messages : 119
    Points : 42
    Points
    42
    Par défaut
    voici le code après modification maintenant aucun message qui s'affiche mais nbrePageFacebookInt prends la valeur 0 car elle initialisé à 0.
    en fait si je fais la transformation de String en int dans la première classe puis je récupère le int dans la deuxième classe le message suivant s'affiche
    Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at reseau.FenetreReseauSocial.getNbrePageFacebookInt(FenetreReseauSocial.java:72)
    at reseau.FenetrePageFacebook$BoutonListener.actionPerformed(FenetrePageFacebook.java:169)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    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
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
     package reseau;
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.IOException;
     
    import java.text.NumberFormat;
     
     
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JFormattedTextField; 
     
    public class FenetreReseauSocial extends JFrame {
     
            /**
             * 
             */
    	private static final long serialVersionUID = 1L;
    		private JPanel container = new JPanel();
            private JFormattedTextField nbrePageFacebook = new JFormattedTextField(NumberFormat.getIntegerInstance());
            private JFormattedTextField ProportionPartage = new JFormattedTextField(NumberFormat.getIntegerInstance());
     
            private JLabel label1 = new JLabel("Nombre de Page Facebook");
            private JLabel label2 = new JLabel("        Proportion de Partage");
            private JButton b = new JButton ("Appliquer");
     
     
     
            public FenetreReseauSocial(){
     
            this.setTitle("Paramètre du Réseau Social");
            this.setSize(400, 200);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setLocationRelativeTo(null);
     
            container.setBackground(Color.white);
            container.setLayout(new BorderLayout());
     
            JPanel top = new JPanel();
     
            Font police = new Font("Arial", Font.BOLD, 14);
            nbrePageFacebook.setFont(police);
            ProportionPartage.setFont(police);
            nbrePageFacebook.setPreferredSize(new Dimension(150, 30));
            ProportionPartage.setPreferredSize(new Dimension(150,30));
            nbrePageFacebook.setForeground(Color.BLUE);
            ProportionPartage.setForeground(Color.BLUE);
            b.addActionListener(new BoutonListener());
            top.add(label1);
            top.add(nbrePageFacebook);
            top.add(label2);
            top.add(ProportionPartage);
     
            top.add(b);
     
     
            this.setContentPane(top);
            this.setVisible(true);            
            }
            public JFormattedTextField getNbrePageFacebookString(){
        		return nbrePageFacebook;
        	}
            public Integer getNbrePageFacebookInt(){
            	String nbrePageFacebookString = getNbrePageFacebookString().getText();
         		Integer nbrePageFacebookInt=Integer.parseInt(nbrePageFacebookString);
         		return nbrePageFacebookInt;
            }
     
        	public JFormattedTextField getProportionPartageString(){
        		return ProportionPartage;
     
        	}
        	public int getProportionPartageInt(){
        		String proportionPartageString = getProportionPartageString().getText();
         		int ProportionPartageInt = Integer.parseInt(proportionPartageString);
        		return ProportionPartageInt;
        	}
            class BoutonListener implements ActionListener{
     
                public void actionPerformed(ActionEvent e) {
     
                        System.out.println("Nbre de Pages Facebook: " + nbrePageFacebook.getText());
                        System.out.println("Proportion de Partage: " + ProportionPartage.getText());
                        int x=getNbrePageFacebookInt();
                		System.out.println(x);
     
     
     
                        setVisible(false);
                        FenetrePageFacebook fn1=new FenetrePageFacebook();
                      fn1.setVisible(true);
     
                }
     
            }
            public static void main(String[] args) throws IOException {
     
            }
     
    }
     
     
     
    package reseau;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.io.IOException;
    import java.text.NumberFormat;
    import java.util.ArrayList;
     
     
     
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFormattedTextField;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
     
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
     
    public class FenetrePageFacebook extends JFrame {
     
            /**
             * 
             */
    	private static final long serialVersionUID = 1L;
    		private JPanel container = new JPanel();
    		private JTextField infoAuteur = new JTextField();
    	    private JFormattedTextField nbreAmis = new JFormattedTextField(NumberFormat.getIntegerInstance());
     
    	    private JComboBox listePolitiquePartage = new JComboBox();
            private JLabel label1 = new JLabel("Politique De Partage");
            private JComboBox listeFrequencePartage=new JComboBox();
            private JLabel label2= new JLabel("Fréquence De Partage");
            private JLabel label3= new JLabel("                Info Auteur  :");
            private JLabel label4= new JLabel("               Nbre d'Amis  :");
            private JButton b = new JButton ("Créer");
     
            ArrayList<PageFacebook> pages=new ArrayList<PageFacebook>();
            FenetreReseauSocial fn;
     
            public FenetrePageFacebook(){
            	String[] tab1 = {"Public", "Amis et leurs Amis", "Amis Seulement", "Personnaliser"};
     
     
        		listePolitiquePartage = new JComboBox(tab1);
    String[] tab2 = {"Fréquence De Partage Elevée", "Fréquence De Partage Moyenne", "Fréquence De Partage Faible"};
     
     
        		listeFrequencePartage = new JComboBox(tab2);
     
            this.setTitle("FenetrePageFacebook");
            this.setSize(400, 300);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setLocationRelativeTo(null);
     
            container.setBackground(Color.white);
            container.setLayout(new BorderLayout());
     
            listePolitiquePartage.setPreferredSize(new Dimension(150,30));
     
            listeFrequencePartage.setPreferredSize(new Dimension(200,30));
     
            infoAuteur.setPreferredSize(new Dimension(150, 30));
            nbreAmis.setPreferredSize(new Dimension(150,30));
            JPanel top = new JPanel();
     
            b.addActionListener(new BoutonListener());
     
            top.add(label3);
            top.add(infoAuteur);
     
            top.add(label4);
            top.add(nbreAmis);
     
            top.add(label1);
            top.add(listePolitiquePartage);
     
            top.add(label2);
            top.add(listeFrequencePartage);
     
            top.add(b);
            listePolitiquePartage.addItemListener(new ItemState());
            listePolitiquePartage.addActionListener(new ItemAction());
            listeFrequencePartage.addItemListener(new ItemState());
            listeFrequencePartage.addActionListener(new ItemAction());
     
            container.add(top);
            this.setContentPane(container);
            this.setVisible(false);
            }
            public JTextField getInfoAuteur(){
        		return infoAuteur;
        	}
     
        	public JFormattedTextField getNbreAmis(){
        		return nbreAmis;
        	}
        	 public class ItemState implements ItemListener {
     
     			@Override
     			public void itemStateChanged(ItemEvent e) {
     				// TODO Auto-generated method stub
     
     
     
     			}
     
     		}
        	 class ItemAction implements ActionListener{
     
                 public void actionPerformed(ActionEvent e) {
     
     
                 }               
         }
     
    public int getNombrepage(){
    	fn=new FenetreReseauSocial();
    	fn.setVisible(false);
    	int nbrePageFacebookInt=0;
    	String nbrePageFacebookString = fn.getNbrePageFacebookString().getText();
    	System.out.println(nbrePageFacebookString);
    	if (!nbrePageFacebookString.equals("")) {
    	 nbrePageFacebookInt=Integer.parseInt(nbrePageFacebookString);
    		}
    	return  nbrePageFacebookInt;
     
     
    }
     
     
     
     
        	 public String getInfoAuteurString(){
        		 String infoAuteurString = getInfoAuteur().getText();
        		 return infoAuteurString;
         	}
        	 public int getNbreAmisInt(){
        		 String nbreAmisString = getNbreAmis().getText();
            		int nbreAmisInt = Integer.parseInt(nbreAmisString);
     
            		return nbreAmisInt;
     
        	 }
        	 public String getPolitiquePartage(){
        		 String politiquePartageSelectionne= (String) listePolitiquePartage.getSelectedItem();
            		return politiquePartageSelectionne;
        	 }
        	 public String getFrequencePartage(){
        		 String frequencePartageSelectionne=(String) listeFrequencePartage.getSelectedItem();
            		return frequencePartageSelectionne;
     
     
        	 }
     
     
     
     
     
        	class BoutonListener implements ActionListener{
     
        	  public void actionPerformed(ActionEvent e) {
        		 int x=getNombrepage();
        		 System.out.println(x);
     
        		  PageFacebook nouvellepage= new PageFacebook();
        		  nouvellepage.IdPage=1;
        		  nouvellepage.InfoAuteur=getInfoAuteurString();
        		  nouvellepage.NbAmis=getNbreAmisInt();
        		  nouvellepage.PolitiquePartage=getPolitiquePartage();
        		  nouvellepage.FrequencePartage=getFrequencePartage();
        		  pages.add(nouvellepage);
        		  System.out.println(pages.size());
        		  System.out.println(pages.get(0).IdPage);
        		  System.out.println(pages.get(0).InfoAuteur);
        		  System.out.println(pages.get(0).NbAmis);
        		  System.out.println(pages.get(0).PolitiquePartage);
        		  System.out.println(pages.get(0).FrequencePartage);
     
     
     
     
     
     
     
     
     
     
     
        	  }
     
        	}
     
    	public static void main(String[] args) throws IOException {
    		// TODO Auto-generated method stub
     
    	}
     
    }
     
     
     
     
    package reseau;
     
    import java.io.IOException;
     
     
     
     
    	public class principal{
     
     
     
     
     
     
     
     
    	/**
             * @param args
             * @throws IOException 
             */
    	public static void main(String[] args) throws IOException {
    		FenetreReseauSocial fn= new FenetreReseauSocial();
    		FenetrePageFacebook fn1=new FenetrePageFacebook();
     
     
     
     
     
     
     
     
    }
    	}

    vraiment je suis bloqué je ne sais pas quoi faire 3 jours je n'ai pas avancé dans ma mémoire. vraiment je suis désolé mais s'il vous plait aidez moi

  12. #12
    Membre confirmé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    540
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vendée (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2009
    Messages : 540
    Points : 532
    Points
    532
    Par défaut
    Il y a tout de même plusieurs choses que je n'arrive pas à saisir dans votre code :

    - pourquoi avoir plusieurs main ?
    - dans une main, vous faites :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     FenetrePageFacebook fn1=new FenetrePageFacebook();
    et la même chose dans le ButtonListener

    Pouvez-vous me dire l'intérêt ?

  13. #13
    Membre du Club
    Inscrit en
    Octobre 2011
    Messages
    119
    Détails du profil
    Informations forums :
    Inscription : Octobre 2011
    Messages : 119
    Points : 42
    Points
    42
    Par défaut
    les main sont inutiles je sais mais à chaque fois que je déclare fn de type FenetreReseauSocial j'ai besoin d'accèder à une variable ou une fonction

    mais comme meme je pense que l'erreur n'est pas là mais aussi je ne sais pas ou

  14. #14
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    107
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 107
    Points : 120
    Points
    120
    Par défaut
    Le probleme c'est que votre variable FN pointe vers une nouvelle classe FenetreReseauSocial. Donc tous ses composant graphique ne sont pas affiché et donc ne possède aucune valeur.

    Pour pouvoir récupérer les valeurs de votre Frame FenetreReseauSocial il faut la passer en paramètre dans le constructeur de FenetrePageFacebook.

    concrètement dans FenetreReseauSocial :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    public void actionPerformed(ActionEvent e) {
    //... 
                        FenetrePageFacebook fn1=new FenetrePageFacebook(this);
    //...
                }
    Et maintenant passer en paramètre FenetreReseauSocial dans le constructeur de la Frame FenetrePageFacebook.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    FenetreReseauSocial fn;
     
    public FenetrePageFacebook(FenetreReseauSocial fn){
         this.fn = fn;
    }
    Ainsi vous aurez accès aux JFormattedText de votre première Frame.

Discussions similaires

  1. [Java] Certification : demande d'information sur SCWCD 5
    Par ganga dans le forum Certifications
    Réponses: 4
    Dernier message: 03/10/2008, 14h05
  2. demande d'informations java ME
    Par eveilside dans le forum Développement 2D, 3D et Jeux
    Réponses: 3
    Dernier message: 06/07/2007, 14h11
  3. Demande d'information pour ajout d'API Java dans eclipse
    Par BernardT dans le forum Eclipse Java
    Réponses: 6
    Dernier message: 07/07/2005, 17h08
  4. [ATL - ActiveX] demande d informations
    Par venomelektro dans le forum MFC
    Réponses: 7
    Dernier message: 22/03/2005, 20h09
  5. Réponses: 3
    Dernier message: 01/02/2004, 21h24

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