Récuperer le texte saisi dans un text field

Fermé
AMINE - 24 mars 2014 à 10:24
Bonjour,


je suis débutant en java,
j'ai une classe qui comporte plusieurs jLabel et JText Field, un bouton 'quitter'
le champs ''identifiant'' je le récupère en passant par une carte électronique, ( c'est bon ça marche )
et une autre classe dans laquelle je me connecte à une base de donnée, et j'affiche les informations correspondantes à un identifiant,

mon problème c'est que, je veux qu'après récupération de l'identifiant avec ma carte, je l'utilise pour afficher les informations correspondantes à cet identifant,

voila le code de deux classes:

//classe 1


package communication;

import java.sql.*;
import javax.swing.JOptionPane;


public class App_graphique extends javax.swing.JFrame {

Statement stmt ;
connect_DB maConnexion = new connect_DB();

// Creates new form App_graphique

public App_graphique() {
initComponents();
CodeBadge=t1;

}
public static javax.swing.JTextField CodeBadge;
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

l1 = new javax.swing.JLabel();
l2 = new javax.swing.JLabel();
l3 = new javax.swing.JLabel();
l4 = new javax.swing.JLabel();
l5 = new javax.swing.JLabel();
t1 = new javax.swing.JTextField();
t2 = new javax.swing.JTextField();
t3 = new javax.swing.JTextField();
t4 = new javax.swing.JTextField();
b3 = new javax.swing.JToggleButton();
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
l6 = new javax.swing.JLabel();
l7 = new javax.swing.JLabel();
l8 = new javax.swing.JLabel();
l9 = new javax.swing.JLabel();
t5 = new javax.swing.JTextField();
t7 = new javax.swing.JTextField();
t6 = new javax.swing.JTextField();
t8 = new javax.swing.JTextField();
t9 = new javax.swing.JTextField();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

l1.setText("votre identifiant est:");

l2.setText("Nom et prénom");

l3.setText("num téléphone");

l4.setText("diréction");

t1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
t1ActionPerformed(evt);
}
});

t4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
t4ActionPerformed(evt);
}
});

b3.setText("Quitter");
b3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
b3MouseClicked(evt);
}
});
b3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b3ActionPerformed(evt);
}
});

jButton1.setText("ENREGISTRER");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jLabel1.setText("privilège_porte_principale");

l6.setText("privilège_étage1");

l7.setText("privilège_étage2");

l8.setText("privilège_bureau_PDG");

l9.setText("privilège_coffre");



//classe 2

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package communication;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class selection_codeBadge {


public static void main(String[] args) throws SQLException, ClassNotFoundException
{


// create our mysql database connection
String myDriver = "org.gjt.mm.mysql.Driver";
String myUrl = "jdbc:mysql://localhost/personnel";
Class.forName(myDriver);
Connection conn = DriverManager.getConnection(myUrl, "root", "");


try {
Statement stmt = conn.createStatement();
try {
ResultSet rs = stmt.executeQuery( "SELECT * FROM personnel_entreprise WHERE identifiant = 'aa123'" );
try {
while ( rs.next() ) {
int numColumns = rs.getMetaData().getColumnCount();
for ( int i = 1 ; i <= numColumns ; i++ ) {
// Column numbers start at 1.
// Also there are many methods on the result set to return
// the column as a particular type. Refer to the Sun documentation
// for the list of valid conversions.
System.out.println( "COLUMN " + i + " = " + rs.getObject(i) );
}
}
} finally {
try { rs.close(); } catch (Throwable ignore) { /* Propagate the original exception
instead of this one that you may want just logged */ }
}
} finally {
try { stmt.close(); } catch (Throwable ignore) { /* Propagate the original exception
instead of this one that you may want just logged */ }
}
} finally {
//It's important to close the connection when you are done with it
try { conn.close(); } catch (Throwable ignore) { /* Propagate the original exception
instead of this one that you may want just logged */ }
}

}
}