Insertion date

momoxx1984 Messages postés 4 Date d'inscription mardi 11 août 2009 Statut Membre Dernière intervention 28 août 2009 - 25 août 2009 à 05:41
ouabida10 Messages postés 57 Date d'inscription mardi 4 août 2009 Statut Membre Dernière intervention 9 janvier 2011 - 28 août 2009 à 02:05
bonjour
je suis débutant en java et j ai un pti soucis au niveau des dates je n y vois vraiment rien !! j ai essayé pas mal de choses et ca donne rien. voila
j ai une interface ou je saisis differentes données sur le client parmi ces données j ai la date de naissance cette derniere est saisie dans un Jtextfield .
je veux deja savoir comment obliger l utilisateur a saisir une date sous le format suivant jj/mm/aaaa et comment je recupere cette date dans netbeans pour l'inserer par la suite avec une requete dans ma table client (mysql)

3 réponses

ouabida10 Messages postés 57 Date d'inscription mardi 4 août 2009 Statut Membre Dernière intervention 9 janvier 2011 1
25 août 2009 à 06:20
salut...... mon ami je te propose 2 solution :

* Tu peux insérer 3 jtextfield un pour le jour ?..et un autre pour le mois?..et un pour l'année??et après vous pouvez récupérer la date sous la forme que vous voulez :
Dans votre cas :
String date= jtextfield1.getText()+jtextfield2.getText()+jtextfield3.getText()

Vous pouvez aussi essayer ce code :

public class ouabida10 extends javax.swing.JFrame {

/** Creates new form ouabida10 */
public ouabida10() {
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() {

jPanel1 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
cbj = new javax.swing.JComboBox();
cbm = new javax.swing.JComboBox();
cba = new javax.swing.JComboBox();
t1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});

jPanel1.setBackground(new java.awt.Color(204, 204, 204));

jLabel3.setText("jour :");

jLabel2.setText("mois :");

jLabel1.setText("année :");

jLabel6.setText("DATE D'ENTRE'E :");

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

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel6)
.addContainerGap(365, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbj, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbm, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cba, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(65, 65, 65))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(5, 5, 5)
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jLabel1)
.addComponent(cba, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cbj, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cbm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addContainerGap(49, Short.MAX_VALUE))
);

t1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N

jButton1.setFont(new java.awt.Font("Comic Sans MS", 1, 24)); // NOI18N
jButton1.setText("teste");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGap(133, 133, 133)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(t1, javax.swing.GroupLayout.DEFAULT_SIZE, 460, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(t1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(23, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

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

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String jour=cbj.getSelectedItem().toString();
String mois=cbm.getSelectedItem().toString();
String anné=cba.getSelectedItem().toString();
String date=jour+"/"+mois+"/"+anné;
t1.setText("la date que vous avez saisie est : "+date);
}

private void formWindowOpened(java.awt.event.WindowEvent evt) {
int[] jo={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};
int[] moi={1,2,3,4,5,6,7,8,9,10,11,12};
int[] ann={2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020};

for(int i=0 ; i<jo.length ;i++){
cbj.addItem(jo[i]);
}

for(int i=0 ; i<moi.length ;i++){
cbm.addItem(moi[i]);
}

for(int i=0 ; i<ann.length ;i++){
cba.addItem(ann[i]);
}

}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ouabida10().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JComboBox cba;
private javax.swing.JComboBox cbj;
private javax.swing.JComboBox cbm;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel6;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField t1;
// End of variables declaration

}
0
momoxx1984 Messages postés 4 Date d'inscription mardi 11 août 2009 Statut Membre Dernière intervention 28 août 2009
28 août 2009 à 01:56
merci bcp !
ca m'aide bcp !!
0
ouabida10 Messages postés 57 Date d'inscription mardi 4 août 2009 Statut Membre Dernière intervention 9 janvier 2011 1
28 août 2009 à 02:05
de rien bon courage
visité ça : ICI
0
Rejoignez-nous