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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
/*
* defIns.java
*
* Created on 20 avril 2007, 11:35
* By Francois Goze
* francoisgoze@gmail.com
*/
package Param;
import Fire.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.Arrays;
import javax.swing.*;
import java.sql.*;
/**
*
*/
public class defInscription extends JFrame{
private BDD mybdd;
private JPanel panneautitre,panneaucentre,panneauboutton;
private JCheckBox affiche[],obligatoire[];
private JButton jOK=new JButton("OK");
private JButton jAnnul=new JButton("Annuler");
private JButton jOption=new JButton("Nouvelle Option");
private int nombre=0;
private String defautcat[]={"Nom","Prenom","Date de Naissance","Telephone","Numero de Licence","Mail","Certificat Medical"};
private String newcat[]=new String[10];
/** Creates a new instance of defIns */
private defInscription(BDD bdd) {
mybdd=bdd;
initBDD();
init(7+nombre);
initactions();
pack();
}
private void init(int i) {
// C est la methode qui me dessine ma fenetre graphique, composée de 3 JPanel et c est celui du milieu qui pose probleme
//Ajout du titre
JOptionPane.showMessageDialog(null,""+nombre);
panneautitre=new JPanel(new GridLayout(1,1,5,5));
panneautitre.add(new JLabel("Definition de la fiche Inscription",JLabel.CENTER));
add(panneautitre,BorderLayout.NORTH);
affiche=new JCheckBox[i];
obligatoire=new JCheckBox[i];
//Ajout du panneau central
panneaucentre=new JPanel(new GridLayout(i+1,3,5,5));
panneaucentre.add(new JLabel("Option"));
panneaucentre.add(new JLabel("Affichée"));
panneaucentre.add(new JLabel("Obligatoire"));
for(int j=0;j<3*i;j++){
if((j-1)%3==0){
//Ajout de la box afficher
affiche[(j-1)/3]=new JCheckBox();
panneaucentre.add(affiche[(j-1)/3]);
}
if((j-2)%3==0){
//Ajout de la box obligatoire
obligatoire[(j-2)/3]=new JCheckBox();
panneaucentre.add(obligatoire[(j-2)/3]);
}
if(j%3==0){
if(j<=18){
panneaucentre.add(new JLabel(defautcat[j/3]));
}else{
panneaucentre.add(new JLabel(newcat[j/3-7]));
}
}
}
add(panneaucentre,BorderLayout.CENTER);
//Ajout du panneau avec les bouttons
panneauboutton=new JPanel(new GridLayout(1,3,5,5));
panneauboutton.add(jOK);
panneauboutton.add(jAnnul);
panneauboutton.add(jOption);
add(panneauboutton,BorderLayout.SOUTH);
}
private void initactions() {
jOK.addActionListener(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null,"OK");
dispose();
}
});
jAnnul.addActionListener(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}
});
jOption.addActionListener(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
//C est ici qu il y a un probleme, quand j appuie sur ce bouton, j'ai un newcat en plus, la ligne se crée mais n affiche rien
mybdd.update("INSERT INTO `infos` ( `nomoption` , `demandee` , `obligatoire` , `valeur` )VALUES ('"+JOptionPane.showInputDialog("Entres une nouvelle nomoption")+"', NULL , NULL , NULL)");
initBDD();
init(7+nombre);
initactions();
pack();
}
});
}
private void initBDD() {
try{
for(int j=0;j<7;j++){
if(!(mybdd.requete("SELECT nomoption FROM infos WHERE nomoption='"+defautcat[j]+"'").first())){
mybdd.update("INSERT INTO `infos` ( `nomoption` , `demandee` , `obligatoire` , `valeur` )VALUES ('"+defautcat[j]+"', NULL , NULL , NULL)");
}
}
ResultSet result=mybdd.requete("SELECT nomoption FROM infos");
while(result.next()){
if(!Arrays.asList(defautcat).contains(result.getString(1)) && !Arrays.asList(newcat).contains(result.getString(1))){
newcat[nombre]=result.getString(1);
++nombre;
}
}
}catch(SQLException ex){
JOptionPane.showMessageDialog(null,"Erreur JDBC : "+ex.getMessage());
}
}
public static void lancer(BDD bdd) {
new defInscription(bdd).setVisible(true);
}
} |