gregenforce7
Messages postés9Date d'inscriptionjeudi 18 décembre 2008StatutMembreDernière intervention30 novembre 2009
-
28 nov. 2009 à 12:32
gregenforce7
Messages postés9Date d'inscriptionjeudi 18 décembre 2008StatutMembreDernière intervention30 novembre 2009
-
30 nov. 2009 à 12:43
Hello,
Je suis débutant en Java. Je travaille avec Eclipse. Mon programme récupére une table d'une base de donnée et l'affiche dans un JTable. Un mot de passe et l'user est demander au démarrage. Je voudrais simplement récupérer un String dans un JtextField et renvoyer ce String dans une variable d'une autre classe. Pour ce faire je fais un return de ma variable vers l'autre classe et j'appel les méthodes dans cette classe. Il m'affiche une erreur me disant qu'il ne trouve pas la source???...
dans une classe je retourne ce qu'il ce trouve dans mes JTextField
kirua12
Messages postés1155Date d'inscriptionsamedi 17 janvier 2004StatutMembreDernière intervention29 avril 20117 29 nov. 2009 à 12:58
IL nous manque pas mal de ton code. Comment tu appelles le constructeur de la classe Database ? l'objet parent est-il bien initialisé ? A quel moment l'appel des méthodes retour1() et retour2() est-il effectué ?
@ouabida : déclarer des variables locales n'est pas vraiment une bonne idée au regard du principe d'encapsulation
GridLayout positionnement2 = new GridLayout(3,2,60,5);
champLabel.setLayout(positionnement2);
boutonFenetre = new JPanel();
FlowLayout positionnement3 = new FlowLayout();
boutonFenetre.setLayout(positionnement3);
verification = new JButton ("Vérifier la connnexion");
connexion = new JButton ("Connexion");
boutonFenetre.add(verification);
boutonFenetre.add(connexion);
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost/Gestion de logement",user,mdp);
conn.close();
JOptionPane.showConfirmDialog(null,
"Connexion établie",
"Juste un test",
JOptionPane.PLAIN_MESSAGE);
champLabel.setBackground (Color.green);
}
catch (Exception ex) {JOptionPane.showMessageDialog(null, "Erreur : Utilisateur ou mot de passe incorrect ", "Attention!!!", JOptionPane.ERROR_MESSAGE);
champLabel.setBackground (Color.red);
}
}
public static void main (String[] args){
Affichage go = new Affichage();
}
gregenforce7
Messages postés9Date d'inscriptionjeudi 18 décembre 2008StatutMembreDernière intervention30 novembre 2009 28 nov. 2009 à 17:34
Salut,
Donc il doit récupérer le contenu de mon JTextField et le mettre dans une variable d'une autre classe.
Si je reste dans la meme classe pas de souci. voici les erreurs affichés :
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at BD.Database$3.actionPerformed(Database.java:105)
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.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)
Merci