Jtextfied

dzleito Messages postés 20 Date d'inscription dimanche 8 mai 2011 Statut Membre Dernière intervention 4 juin 2012 - 1 juin 2012 à 02:19
dzleito Messages postés 20 Date d'inscription dimanche 8 mai 2011 Statut Membre Dernière intervention 4 juin 2012 - 1 juin 2012 à 10:34
j'ai ajouter un membre dans une inscription
qu'an je l'ajoute a ma base je lui affiche un msg qui lui indique un que l'opération et bien faite
alor il vas y'accé a une autre fenétre qui contient des operation
comment je peut avoit le nom qu'il a tapé dans le formulaire pour l'utilisé dans cet nouvelle fenétre , et que ma base contien pleur inscrit .
merçi

4 réponses

cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 371
1 juin 2012 à 08:28
Salut,

Ce que tu veux afficher dans la deuxième fenêtre, tu peux le mettre en paramètre de sont constructeur.
public class Fenetre2 extends JFrame{

   public Fenetre2(String aAfficher){
      add(new JLabel(aAfficher));
      setSize(200, 200);
      setVisible(true);
   }

}
0
dzleito Messages postés 20 Date d'inscription dimanche 8 mai 2011 Statut Membre Dernière intervention 4 juin 2012
1 juin 2012 à 10:18
Voila le fichier que je veut lui ajouter la variable de l'inscription

package javaapplication;
import com.mysql.jdbc.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import java.sql.ResultSet;
import java.util.Random;
import java.util.Vector;

public class conduite extends javax.swing.JFrame {


int i=0;

int compteurTest=0;
int NOMBRE_TEST=2;
Vector testTable=new Vector();
conecteur_test t = new conecteur_test();
String [][]mm= new String[3][4];

int score=20;
int resultat;

public conduite() {

initComponents();

testTable.add(i);
}


@SuppressWarnings("unchecked")
//
private void initComponents() {

jLabel1 = new javax.swing.JLabel();
gaucheBoutton = new javax.swing.JButton();
avanceBoutton = new javax.swing.JButton();
droiteBoutton = new javax.swing.JButton();
ralentirBoutton = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
demareBoutton = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

gaucheBoutton.hide();
gaucheBoutton.setText("gauche");
gaucheBoutton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
gaucheBouttonActionPerformed(evt);
}
});

avanceBoutton.hide();
avanceBoutton.setText("Avancer");
avanceBoutton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
avanceBouttonActionPerformed(evt);
}
});

droiteBoutton.hide();
droiteBoutton.setText("droite");
droiteBoutton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
droiteBouttonActionPerformed(evt);
}
});

ralentirBoutton.hide();
ralentirBoutton.setText("Ralentir");
ralentirBoutton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ralentirBouttonActionPerformed(evt);
}
});

demareBoutton.setText("demarer");
demareBoutton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
demareBouttonActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGap(8, 8, 8)
.addComponent(demareBoutton)
.addGap(30, 30, 30)
.addComponent(gaucheBoutton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(ralentirBoutton)
.addGroup(layout.createSequentialGroup()
.addComponent(avanceBoutton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(droiteBoutton)))
.addContainerGap(79, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(60, 60, 60)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 279, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(64, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 384, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(demareBoutton)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(gaucheBoutton)
.addComponent(avanceBoutton)
.addComponent(droiteBoutton))
.addGap(29, 29, 29))
.addComponent(ralentirBoutton))
.addGap(48, 48, 48))
);

pack();
}//

private void droiteBouttonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:

try {
mm=t.conduite();
String rep="droite";
if (compteurTest< NOMBRE_TEST){
rep.toString();
if(rep.equals(mm[i][2])){ //si la réponse du condidat est la méme que celle dans la bd
JOptionPane.showMessageDialog(null, "Bonne reponse");
compteurTest++;
do
{
i=new Random().nextInt(3);
}
while(testTable.contains(i));
testTable.add(i);
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource(mm[i][0]))); //aficher l'image
jLabel2.setText(mm[i][1]); //afficher la question


}else{

score=(score-Integer.parseInt(mm[i][3]));

compteurTest++;


JOptionPane.showMessageDialog(null, "Movaise reponse");
do
{
i=new Random().nextInt(3);
}
while(testTable.contains(i));
testTable.add(i);
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource(mm[i][0]))); //aficher l'image
jLabel2.setText(mm[i][1]);





}
}else{

if(rep.equals(mm[i][2])){ JOptionPane.showMessageDialog(null, "Bonne reponse");


JOptionPane.showMessageDialog(null, "Terminer! Votre score est: "+score);}
else{

score=(score-Integer.parseInt(mm[i][3]));

JOptionPane.showMessageDialog(null, "Movaise reponse");
JOptionPane.showMessageDialog(null, "Terminer ! Votre score est: "+score);






}}

} catch (ClassNotFoundException ex) {
Logger.getLogger(tst.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(tst.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(tst.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(tst.class.getName()).log(Level.SEVERE, null, ex);
}



}

private void demareBouttonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
gaucheBoutton.show();
avanceBoutton.show();
droiteBoutton.show();
ralentirBoutton.show();
try {
mm=t.conduite();

jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource(mm[i][0]))); //afficher l'image
jLabel2.setText(mm[i][1]); //afficher la question
demareBoutton.setVisible(false);





} catch (ClassNotFoundException ex) {
Logger.getLogger(tst.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(tst.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(tst.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(tst.class.getName()).log(Level.SEVERE, null, ex);
}
}

private void gaucheBouttonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {

mm=t.conduite();
String rep="gauche";
if (compteurTest
0
dzleito Messages postés 20 Date d'inscription dimanche 8 mai 2011 Statut Membre Dernière intervention 4 juin 2012
1 juin 2012 à 10:21
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é :/
0
dzleito Messages postés 20 Date d'inscription dimanche 8 mai 2011 Statut Membre Dernière intervention 4 juin 2012
1 juin 2012 à 10:34
car je veux noter le membre qui a inscrit
0
Rejoignez-nous