et voila le fichier qui contien le Jtextfield que je l'ai mis dans une variable "YAC"
package javaapplication;
import java.sql.*;
import javax.swing.*;
/**
*
* @author Yacine
*/
public class inscription extends javax.swing.JFrame {
Connection conn = null;
ResultSet rs = null;
PreparedStatement pst = null;
public String yac;
/** Creates new form inscription */
public inscription() {
initComponents();
}
/** 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() {
jPasswordField1 = new javax.swing.JPasswordField();
jPasswordField2 = new javax.swing.JPasswordField();
jLabel4 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setMinimumSize(new java.awt.Dimension(430, 450));
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
getContentPane().setLayout(null);
getContentPane().add(jPasswordField1);
jPasswordField1.setBounds(140, 170, 127, 30);
getContentPane().add(jPasswordField2);
jPasswordField2.setBounds(140, 230, 127, 30);
jLabel4.setText("Verification");
getContentPane().add(jLabel4);
jLabel4.setBounds(33, 240, 70, 14);
jLabel2.setText("Mot de Pass");
getContentPane().add(jLabel2);
jLabel2.setBounds(28, 180, 80, 14);
jLabel1.setText("Pseudo ");
getContentPane().add(jLabel1);
jLabel1.setBounds(28, 120, 60, 14);
getContentPane().add(jTextField1);
jTextField1.setBounds(140, 110, 129, 30);
jButton1.setText("Valider");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1);
jButton1.setBounds(220, 373, 80, 30);
jButton2.setText("Annuler");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
getContentPane().add(jButton2);
jButton2.setBounds(119, 373, 90, 30);
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
jPanel1.setLayout(null);
jLabel3.setIcon(new javax.swing.ImageIcon("C:\\Users\\Yacine\\Desktop\\inscription-2.gif")); // NOI18N
jPanel1.add(jLabel3);
jLabel3.setBounds(70, 0, 360, 400);
getContentPane().add(jPanel1);
jPanel1.setBounds(0, 0, 420, 420);
pack();
}// </editor-fold>
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText("");
jPasswordField1.setText("");
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int x = jPasswordField1.getText().length();
int y = jTextField1.getText().length();
if (jPasswordField1.getText().equals(jPasswordField2.getText()))
{
if (x>=6&&y>=3){
String sql = "INSERT INTO tblelogin (username, userpass) values(?, ?)";
try{
pst = conn.prepareStatement(sql);
pst.setString(1, jTextField1.getText());
pst.setString(2, jPasswordField1.getText());
pst.execute();
yac=jTextField1.getText();
setVisible(false);
JOptionPane.showMessageDialog(null, "Enregistrer avec succé ! bienvenue cher "+yac);
new choix().show();
} catch (Exception e){
JOptionPane.showMessageDialog(null, e);
}}
else{JOptionPane.showMessageDialog(null, "Veiller remplir vos champs corectement");
jTextField1.setText("");
jPasswordField1.setText("");
jPasswordField2.setText("");
}
}
else{
JOptionPane.showMessageDialog(null, "mot de passe ne correspend pas ");
}
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
conn = mysqlconnect.ConnectDb2();
}
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(inscription.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(inscription.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(inscription.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(inscription.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new inscription().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JPasswordField jPasswordField2;
private javax.swing.JTextField jTextField1;
// End of variables declaration
}
sa na pas marché :/