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 :

Problem Java interface


Sujet :

Interfaces Graphiques en Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Février 2008
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Février 2008
    Messages : 9
    Par défaut Problem Java interface
    Bonjour les développeurs,
    J'ai un souci avec une classe java, voila je vous explique, j'ai récupérer un 2 string, Mot de pass et Id, mais la comparaison ne se fait pas, ou plus tot la suite du programme ne marche pas, svp quelqu'un peut m'aider !!
    voici le 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
    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
     
    package Ulb;
    import com.jgoodies.forms.layout.FormLayout;
    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ComponentAdapter;
    import java.awt.event.KeyAdapter;
    import javax.swing.ButtonGroup;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JPasswordField;
    import javax.swing.JRadioButton;
    import javax.swing.JTextField;
     
    import javax.swing.WindowConstants;
    import javax.swing.SwingUtilities;
    import java.sql.*;
    import java.util.Arrays;
    import java.awt.event.* ;
    import javax.swing.JOptionPane;
     
     
     
    /**
    * This code was edited or generated using CloudGarden's Jigloo
    * SWT/Swing GUI Builder, which is free for non-commercial
    * use. If Jigloo is being used commercially (ie, by a corporation,
    * company or business for any purpose whatever) then you
    * should purchase a license for each developer using Jigloo.
    * Please visit <a href="http://www.cloudgarden.com/" target="_blank">www.cloudgarden.com</a> for details.
    * Use of Jigloo implies acceptance of these licensing terms.
    * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
    * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
    * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
    */
    public class Acceuil extends javax.swing.JFrame {
        private JLabel jLabel1;
        private JLabel jLabel2;
        private JLabel jLabel3;
        private JLabel jLabel4;
        private JButton jButton1;
        private ButtonGroup buttonGroup1;
        private JPasswordField jPasswordField1;
        private JTextField jTextField1;
        private JButton jButton2;
        private JRadioButton jRadioButton2;
        private JRadioButton jRadioButton1;
     
        /**
        * Auto-generated main method to display this JFrame
        */
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    Acceuil inst = new Acceuil();
                    inst.setLocationRelativeTo(null);
                    inst.setVisible(true);
     
                }
            });
        }
     
        public Acceuil() {
            super();
            initGUI();
     
        }
     
        private void initGUI() {
            try {
                GridBagLayout thisLayout = new GridBagLayout();
                thisLayout.rowWeights = new double[] {0.1, 0.1, 0.1, 0.1};
                thisLayout.rowHeights = new int[] {7, 7, 7, 7};
                thisLayout.columnWeights = new double[] {0.1, 0.1, 0.1, 0.1};
                thisLayout.columnWidths = new int[] {7, 7, 7, 7};
                getContentPane().setLayout(thisLayout);
                this.setTitle("Fenetre Principale");
                this.setResizable(false);
                setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
     
                {
                    jLabel1 = new JLabel();
                    getContentPane().add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
                    jLabel1.setText("Admin");
                }
                {
                    jLabel2 = new JLabel();
                    getContentPane().add(jLabel2, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
                    jLabel2.setText("User");
                }
                {
                    jRadioButton1 = new JRadioButton();
                    getContentPane().add(jRadioButton1, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(1, 0, 0, 0), 0, 0));
                    jRadioButton1.setText("");
                }
                {
                    jRadioButton2 = new JRadioButton();
                    getContentPane().add(jRadioButton2, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
                    jRadioButton2.setText("");
                }
                {
                    jLabel3 = new JLabel();
                    getContentPane().add(jLabel3, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
                    jLabel3.setText("Id");
                }
                {
                    jLabel4 = new JLabel();
                    getContentPane().add(jLabel4, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
                    jLabel4.setText("PassW");
                }
                {
                    jButton1 = new JButton();
                    getContentPane().add(jButton1, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
                    jButton1.setText("Ok");
                    jButton1.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {    
                               Connection conn = null;
                               Statement instruction = null;
                               ResultSet rs = null;
     
     
     
                               String nom = jTextField1.getText();
                               String pass = jPasswordField1.getText(); 
                               String url = "jdbc:mysql://localhost/projetUlb";
                               String login = "root";
                               String passw = "root";
     
                               try{
                                   if(jRadioButton1.isSelected())
                                         {
                                          System.out.print(nom);
                                          System.out.print(pass);
                                          if (nom.equals("") || pass.equals(""))
                                          {
     
                                              jButton1.setEnabled(false); 
                                            JOptionPane.showMessageDialog(null,"");
                                            jTextField1.setText("");
                                               jPasswordField1.setText("");
                                               jButton1.setEnabled(true);
                                          }
                                         else 
                                              if (nom.equals(login) && pass.equals(passw))
                                           {
                                              Administrateur admis = new Administrateur();
                                            admis.setVisible(true);
                                            }
     
                                           }
     
                                   else if(jRadioButton2.isSelected())
                                    {
     
                                      try{
                                      Class.forName("com.mysql.jdbc.Driver");
                                      }catch(Exception ex){}
                                      conn = DriverManager.getConnection(url,login,passw);
                                      instruction = conn.createStatement();
                                      rs = instruction.executeQuery("SELECT user,password FROM projetulb.compte ");
     
                                  while(rs.next())
                                      {
                                          String id,pas;
                                          id = rs.getString(2);
                                          pas = rs.getString(3);
                                          if (nom.equals(id) && pass.equals(pas))
                                          {
                                               new User().setVisible(true);
                                          }
                                 }
                                   }
                               rs.close();
                               instruction.close();
                               conn.close();
                                }
     
                           catch(Exception e1)
                           {
                           System.out.println(e1);  
                        }                                        
     
                               finally{
                                   if(instruction !=null){try{instruction.close();}catch(Exception e1){e1.printStackTrace();}}
                                   if(instruction !=null){try{instruction.close();}catch(Exception e1){e1.printStackTrace();}}
                               }
                        }
                    });
     
                }
                {
                    jButton2 = new JButton();
                    getContentPane().add(jButton2, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
                    jButton2.setText("Cancel");
                    jButton2.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
     
                        }
                    });
     
                }            
                {
                    jTextField1 = new JTextField();
                    getContentPane().add(jTextField1, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
                    jTextField1.setText("         ");
                }
                {
                    jPasswordField1 = new JPasswordField();
                    getContentPane().add(jPasswordField1, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
                    jPasswordField1.setText("        ");
                    jPasswordField1.setEchoChar('*');
     
     
                }    
                {
                    ButtonGroup buttonGroup1 = new ButtonGroup();
                    buttonGroup1.add(jRadioButton1);
                    buttonGroup1.add(jRadioButton2);
                }
     
                pack();
            } catch (Exception e) {
                e.printStackTrace();
            }
     
        }    
     
    }

    Pour la classe Administrateur c'est une simple JFrame

    Mercii

  2. #2
    Membre habitué
    Profil pro
    Inscrit en
    Février 2008
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Février 2008
    Messages : 9
    Par défaut avec un debug
    j'ai essayer ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    if (login.equals(login) && passw.equals(passw))
                                           {
                              Administrateur admis = new Administrateur();
                                            admis.setVisible(true);
                                            }
    et ça marché, donc le probleme est dans la comparaison mais j'arrive pas a le serné

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    String nom = jTextField1.getText();
    String pass = jPasswordField1.getText(); 
    String url = "jdbc:mysql://localhost/projetUlb";
    String login = "root";
    String passw = "root";

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Février 2008
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Février 2008
    Messages : 9
    Par défaut probleme regler :)
    le truc été, dans le jtextField.settext() !!!
    j'ai supprimé cette ligne et ça marche

Discussions similaires

  1. Problème java.net.SocketException sous linux
    Par loop4 dans le forum Linux
    Réponses: 2
    Dernier message: 27/04/2006, 15h42
  2. probleme java 1.5 (affichage applet)
    Par argon dans le forum AWT/Swing
    Réponses: 21
    Dernier message: 19/03/2006, 12h26
  3. [Kylix] Fedora 4 / Kylix3 Problem d'interface.
    Par bozoeus dans le forum EDI
    Réponses: 1
    Dernier message: 11/08/2005, 19h27
  4. [Exception]Probleme : Java.lang.Exception
    Par Nico66 dans le forum Général Java
    Réponses: 6
    Dernier message: 09/05/2005, 12h06
  5. Problème Visu Interface Graphique
    Par Bweb dans le forum Applications et environnements graphiques
    Réponses: 12
    Dernier message: 16/08/2004, 15h52

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