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

AWT/Swing Java Discussion :

Problème avec actionPerformed() unknown source


Sujet :

AWT/Swing Java

  1. #1
    Membre actif Avatar de janyoura
    Femme Profil pro
    étudiante ingénierie informatique
    Inscrit en
    Mars 2012
    Messages
    365
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : étudiante ingénierie informatique

    Informations forums :
    Inscription : Mars 2012
    Messages : 365
    Points : 279
    Points
    279
    Par défaut Problème avec actionPerformed() unknown source
    Bonjour,
    J'ai une interface d'authentification, et je dois effectuer la vérification du login et mot de passe tapé en passant par la base de données, j'ai donc fais ce code mais lorsque j'exécute la classe, j'obtient une erreur lorsque je clique sur le bouton "login", de meme en cliquant sur "cancel".
    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
    package workflow.interfaces;
     
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
     
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPasswordField;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
     
    public class UserLogin extends JFrame {
     
    	  private Statement statement;
    	  private ResultSet rs;
    	  private JTextArea errorText;
     
    	  private String passVerif;
    	  private int id_entreprise;
     
     
    	JButton login, cancel;
    	JTextField uname;
    	JPasswordField pass;
    	JLabel u,p;
     
    	public UserLogin(){
    		setTitle("Login");
    		setLayout(new GridLayout(3,2));
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    		setVisible(true);
     
    		u = new JLabel("Username");
    		p = new JLabel("Password");
     
    		uname = new JTextField(20);
    		pass = new JPasswordField(20);
     
    		login = new JButton("Login");
    		cancel = new JButton("Cancel");
     
    		add(u);
    		add(uname);
     
    		add(p);
    		add(pass);
     
    		add(login);
    		add(cancel);
     
     
    		uname.requestFocus();
     
    		login.addActionListener(new ActionListener() {
     
    			@Override
    			public void actionPerformed(ActionEvent arg0) {
    				String un=uname.getText();
    				String pa= new String(pass.getPassword());
    				connectToDB();
    				 try {
    					rs = statement.executeQuery("SELECT * FROM entreprise WHERE login = " + un);
     
    					/* si le login existe dans la base de données 
    					alors récuperer le password et vérifier sa correspondance */
     
    					while (rs.next()){	
    						id_entreprise = rs.getInt("id_entreprise");
    					//	String nom_entreprise = rs.getString("nom_entr");
    					//	String login = rs.getString("login");
    						passVerif = rs.getString("passe");
    						int row = rs.getRow();
    						System.out.println("Données contenues dans la ligne "+row);
    						System.out.println("id entreprise : "+id_entreprise);
     
    						if ((pa.equals(passVerif))){
    							dispose();
    							new WelcomeFrame();
     
    						}
    						else  errorText.append("Veuillez resaisir votre mot de passe");
    					}
     
    				} catch (SQLException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    				}
     
     
    			}
     
    		});
    		KeyAdapter k = new KeyAdapter(){
    			public void KeyPressed(KeyEvent ke){
    				if (ke.getKeyCode() == KeyEvent.VK_ENTER)
    					login.doClick();
     
    			}
     
    		};
    		pass.addKeyListener(k);
    		uname.addKeyListener(k);
     
    		pack();
    		setLocationRelativeTo(null);
    	}
    	public void connectToDB() {
    	    try {
    	     Connection connection = DriverManager
    	          .getConnection("jdbc:mysql://localhost:3306/destockage", "xxx", "xxxx");
    	     Statement statement = connection.createStatement();
     
    	    } catch (SQLException connectException) {
    	      System.out.println(connectException.getMessage());
    	      System.out.println(connectException.getSQLState());
    	      System.out.println(connectException.getErrorCode());
    	      System.exit(1);
    	    }
    	  }
     
     
     
    	public static void main(String[] args) {
     
    		 try {
    		      Class.forName("com.mysql.jdbc.Driver").newInstance();
    		    } catch (Exception e) {
    		      System.err.println("Unable to find and load driver");
    		      System.exit(1);
    		    }
     
    		new UserLogin();
     
    	}
     
    }
    Erreur:

    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
    connexion bd établie
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at workflow.interfaces.UserLogin$1.actionPerformed(UserLogin.java:71)
    	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$200(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue$4.run(Unknown Source)
    	at java.awt.EventQueue$4.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$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)
    Que pourra être le problème?
    Merci pour votre aide
    "Scientists dream about doing great things. Engineers do them.”

    La réussite après tant de travail est un sentiment à vivre

    Si ton message est résolu, il y a un bouton qui est fait pour ça :
    Il se trouve tout en bas de la conversation !

    N'oublie pas que si ce message t'as aidé, tu peux voter pour lui en utilisant

  2. #2
    Membre actif
    Homme Profil pro
    Ingénieur de construction de réseaux
    Inscrit en
    Août 2012
    Messages
    406
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Ingénieur de construction de réseaux
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2012
    Messages : 406
    Points : 235
    Points
    235
    Par défaut
    Citation Envoyé par janyoura Voir le message
    Que pourra être le problème?
    Merci pour votre aide
    En principe cet erreur signifie que utilise une variable que tu n'a pas déclaré ce que je veux savoir c'est si l'erreur est complète car je n'arrive pas a voir a quelle ligne il y a problème
    La force d'un programmeur ne réside pas dans le fait qu'il écrive des codes puissants mais dans sa capacité à les maintenir!!!

  3. #3
    Modérateur
    Avatar de dinobogan
    Homme Profil pro
    ingénieur
    Inscrit en
    Juin 2007
    Messages
    4 073
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : ingénieur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 4 073
    Points : 7 163
    Points
    7 163
    Par défaut
    Ton objet "statement" n'est pas déclaré.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java
    Que la force de la puissance soit avec le courage de ta sagesse.

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

Discussions similaires

  1. Problème avec "/etc/apt/sources.list". Impossible d'ouvrir Synaptic !
    Par Komsa dans le forum Administration système
    Réponses: 1
    Dernier message: 16/10/2009, 18h02
  2. problème avec ce code source..
    Par Imène_23 dans le forum Images
    Réponses: 25
    Dernier message: 04/06/2009, 18h25
  3. Problème avec mail (code source affiché au lieu du mail)
    Par Gunner4902 dans le forum Thunderbird
    Réponses: 0
    Dernier message: 03/04/2008, 14h06
  4. probléme avec le kernel source
    Par yous18 dans le forum Administration système
    Réponses: 0
    Dernier message: 21/03/2008, 14h48
  5. problème avec un code source JAVA
    Par magicbisous-nours dans le forum SQL
    Réponses: 7
    Dernier message: 10/12/2007, 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