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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
programme client :
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class Programme extends Applet{
// Les objets globaux
TextField txNom, txPostnom, txAdresseCandidat, txNationalite, txNomEcoleFrequente, txSectionSuiviHumanite, txPourcentage, txAnneeAcademique;
Choice chSexe, chEtatCivil, chReferenceSection;
// variables globales
String strNom, strPostnom, strSexe, strEtatCivil, strAdresseCandidat, strNationalite, strNomEcoleFrequente, strSectionSuiviHumanite,
strPourcentage, strReferenceSection, strAnneeAcademique, requete1, requete2;
public void init(){
// disposition d'éléments
setLayout(null);
setBackground(Color.gray);
// Différentes fontes à utiliser
Font fonte1= new Font("TimesRoman", Font.PLAIN, 14);
Font fonte2= new Font("TimesRoman", Font.BOLD, 20);
Font fonte3= new Font("TimesRoman", Font.ITALIC + Font.BOLD, 14);
// En-tête :
JLabel lbIcone = new JLabel();
lbIcone.setIcon(new ImageIcon("D:\\pido\\jdk1.5.0_14\\bin\\LOGO ISTA.jpg"));
add(lbIcone);
lbIcone.setBounds(300, 80, 100, 100);
Label lbRDC = new Label("REPUBLIQUE DEMOCRATIQUE DU CONGO");
lbRDC.setBounds(30, 30, 420, 25);
add(lbRDC); lbRDC.setFont(fonte2);
Label lbMINIST = new Label("MINISTERE DE L'EDUCATION UNIVERSITAIRE ET SUPERIEURE");
lbMINIST.setBounds(30,60,700,25);
add(lbMINIST); lbMINIST.setFont(fonte2);
Label lbEntete = new Label("FORMULAIRE D'INSCRIPTION A L'ISTA");
lbEntete.setBounds(100,190,700,28); add(lbEntete); lbEntete.setFont(fonte2);
Label lblIdentite = new Label("I. IDENTITE");
add(lblIdentite); lblIdentite.setBounds(10, 230, 90, 23);
lblIdentite.setFont(new Font("Dialog", 1, 16));
Label lblEtudeSecondaireFaite = new Label("II. ETUDES SECONDAIRES FAITES");
add(lblEtudeSecondaireFaite); lblEtudeSecondaireFaite.setBounds(10, 490, 300, 23);
lblEtudeSecondaireFaite.setFont(new Font("Dialog", 1, 16));
Label lblChoixFormule = new Label("VI. CHOIX FORMULES");
add(lblChoixFormule); lblChoixFormule.setBounds(10, 640, 200, 23);
lblChoixFormule.setFont(new Font("Dialog", 1, 14));
// Labels et Textfields
Label lbNom = new Label("1. NOM"); lbNom.setBounds(30, 270, 60, 22);
add(lbNom); lbNom.setFont(fonte3);
txNom = new TextField(); txNom.setBounds(120, 270, 240, 22);
add(txNom); txNom.setFont(fonte1);
Label lbPostnom = new Label("2. POSTNOM"); lbPostnom.setBounds(30, 310, 100, 22);
add(lbPostnom); lbPostnom.setFont(fonte3);
txPostnom = new TextField(); txPostnom.setBounds(140, 310, 300, 22);
add(txPostnom); txPostnom.setFont(fonte1);
Label lbSexe = new Label("3. SEXE"); lbSexe.setBounds(30, 350, 60, 22);
add(lbSexe); lbSexe.setFont(fonte3);
chSexe = new Choice(); chSexe.setBounds(110, 350, 140, 22);
add(chSexe); chSexe.setFont(fonte1);
chSexe.addItem(" "); chSexe.addItem("Masculin"); chSexe.addItem("Féminin");
Label lbEtatCivil = new Label("4. ETAT CIVIL"); lbEtatCivil.setBounds(350, 350, 120, 22);
add(lbEtatCivil); lbEtatCivil.setFont(fonte3);
chEtatCivil = new Choice(); chEtatCivil.setBounds(490, 350, 200, 22);
add(chEtatCivil); chEtatCivil.setFont(fonte1);
chEtatCivil.addItem(" ");chEtatCivil.addItem("MARIE(E)");
chEtatCivil.addItem("CELIBATAIRE");chEtatCivil.addItem("DIVORCE");chEtatCivil.addItem("VEUF(VE)");
Label lbAdresseCandidat = new Label("5. ADRESSE DU CANDIDAT"); lbAdresseCandidat.setBounds(30, 400, 200, 22);
add(lbAdresseCandidat); lbAdresseCandidat.setFont(fonte3);
txAdresseCandidat = new TextField(); txAdresseCandidat.setBounds(250, 400, 300, 22);
add(txAdresseCandidat); txAdresseCandidat.setFont(fonte1);
Label lbNationalite = new Label("6. NATIONALITE"); lbNationalite.setBounds(30, 450, 130, 22);
add(lbNationalite); lbNationalite.setFont(fonte3);
txNationalite = new TextField(); txNationalite.setBounds(180, 450, 280, 22);
add(txNationalite); txNationalite.setFont(fonte1);
Label lbNomEcoleFrequente = new Label("7. NOM ECOLE SECONDAIRE FREQUENTE"); lbNomEcoleFrequente.setBounds(30, 530, 320, 22);
add(lbNomEcoleFrequente); lbNomEcoleFrequente.setFont(fonte3);
txNomEcoleFrequente = new TextField(); txNomEcoleFrequente.setBounds(350, 530, 350, 22);
add(txNomEcoleFrequente); txNomEcoleFrequente.setFont(fonte1);
Label lbSectionSuiviHumanite = new Label("8. SECTION SUIVIE AUX HUMANITES"); lbSectionSuiviHumanite.setBounds(30, 570, 250, 22);
add(lbSectionSuiviHumanite); lbSectionSuiviHumanite.setFont(fonte3);
txSectionSuiviHumanite = new TextField(); txSectionSuiviHumanite.setBounds(290, 570, 340, 22);
add(txSectionSuiviHumanite); txSectionSuiviHumanite.setFont(fonte1);
Label lbPourcentage = new Label("9. POURCENTAGE DU DIPLOME"); lbPourcentage.setBounds(30, 600, 230, 22);
add(lbPourcentage); lbPourcentage.setFont(fonte3);
txPourcentage = new TextField(2); txPourcentage.setBounds(290, 600, 120, 22);
add(txPourcentage); txPourcentage.setFont(fonte1);
Label lbReferenceSection = new Label("10. REFERENCE SECTION"); lbReferenceSection.setBounds(30, 670, 150, 22);
add(lbReferenceSection); lbReferenceSection.setFont(fonte3);
chReferenceSection = new Choice(); chReferenceSection.setBounds(180, 670, 190, 22);
add(chReferenceSection); chReferenceSection.setFont(fonte1);
chReferenceSection.addItem(" "); chReferenceSection.addItem("PREPARATOIRE"); chReferenceSection.addItem("ELECTRONIQUE");
chReferenceSection.addItem("ELECTRICITE"); chReferenceSection.addItem("AVIATION");chReferenceSection.addItem("GENIE ELECTRIQUE");
Label lbAnneeAcademique = new Label("11. ANNEE ACADEMIQUE"); lbAnneeAcademique.setBounds(30, 700, 180, 22);
add(lbAnneeAcademique); lbAnneeAcademique.setFont(fonte3);
txAnneeAcademique = new TextField(4); txAnneeAcademique.setBounds(220, 700, 230, 22);
add(txAnneeAcademique); txAnneeAcademique.setFont(fonte1);
Label lblJeCertifie = new Label("Je certifie en mon honneur que les renseignement fournis ci-haut sont exacts");
add(lblJeCertifie); lblJeCertifie.setBounds(30, 750, 520, 23); lblJeCertifie.setFont(new Font("Dialog", 2, 14));
// Button Soumettre
Button btSoumettre = new Button("Soumettre"); btSoumettre.setBounds(560,410,140,27);
add(btSoumettre); btSoumettre.setFont(fonte1);
// Button Annuler
Button btAnnuler = new Button("Annuler"); btAnnuler.setBounds(560,460,140,27);
add(btAnnuler); btAnnuler.setFont(fonte1);
// Clic sur le bouton Annuler
btAnnuler.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
txNom.setText(null); txPostnom.setText(null); txAdresseCandidat.setText(null); txNationalite.setText(null);
txNomEcoleFrequente.setText(null); txSectionSuiviHumanite.setText(null); txPourcentage.setText(null); txAnneeAcademique.setText(null);
}
}
);
// Clic sur le bouton soumettre
btSoumettre.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
soumission(e);
}
}
);
} // Fin méthode init
public void soumission(ActionEvent evt){
//récupération des données dans les variables globales
strNom = txNom.getText(); strPostnom = txPostnom.getText(); strAdresseCandidat = txAdresseCandidat.getText();
strNationalite = txNationalite.getText(); strNomEcoleFrequente =txNomEcoleFrequente.getText();
strSectionSuiviHumanite = txSectionSuiviHumanite.getText(); strPourcentage = txPourcentage.getText();
strAnneeAcademique = txAnneeAcademique.getText(); strSexe = chSexe.getSelectedItem();
strEtatCivil = chEtatCivil.getSelectedItem(); strReferenceSection = chReferenceSection.getSelectedItem();
// contruction de la requête sql
requete1 = "insert into CANDIDAT (NOM, POSTNOM, SEXE, ETATCIVIL, ADRESSECANDIDAT, NATIONALITE, NOMECOLESECONDAIREFREQUENTE,"+
"SECTIONHUMANITESUIVIE, POURCENTAGE, REFERENCESECTION, ANNEEACADEMIQUE)" + " values ('" + strNom +"','"+ strPostnom +"','"+ strSexe +
"','"+ strEtatCivil +"','"+ strAdresseCandidat +"','"+ strNationalite +"','"+ strNomEcoleFrequente +"','"+ strSectionSuiviHumanite +
"','"+ strPourcentage +"','"+ strReferenceSection +"','"+ strAnneeAcademique + "')";
requete2 = "select * from CANDIDAT where NOM ='"+strNom+"' and POSTNOM ='"+strPostnom+"' and SEXE ='"+strSexe+
"' and ETATCIVIL ='"+strEtatCivil+"' and ADRESSECANDIDAT ='"+strAdresseCandidat+"' and NATIONALITE ='"+strNationalite+
"' and NOMECOLESECONDAIREFREQUENTE ='"+strNomEcoleFrequente+"' and SECTIONHUMANITESUIVIE ='"+strSectionSuiviHumanite+
"' and POURCENTAGE ='"+strPourcentage+"' and REFERENCESECTION ='"+strReferenceSection+"' and ANNEEACADEMIQUE ='"+strAnneeAcademique+"'";
// Connection au serveur
Socket socket = null;
try{
socket = new Socket("127.0.0.1", 8080);
} catch(Exception e){
JOptionPane.showMessageDialog(null, "Echec connexion serveur",
"Echec connexion serveur" +e, JOptionPane.WARNING_MESSAGE);
System.exit(1);
}
// Création du flux d'entrée et sortie
PrintWriter Out = null;
BufferedReader In = null;
try{
In = new BufferedReader(new InputStreamReader(socket.getInputStream()));
Out = new PrintWriter(socket.getOutputStream(),true);
} catch(Exception e){
JOptionPane.showMessageDialog(null, "Echec création flux de sortie",
"Echec création flux de sortie", JOptionPane.WARNING_MESSAGE);
System.exit(2);
}
// envoi de la requête et réception notofocation serveur
Out.println(requete1);
Out.println(requete2);
String reponse = "";
try{
reponse = In.readLine();
} catch (Exception e){
JOptionPane.showMessageDialog(null, "Erreur lecture réponse du serveur", "Notification",
JOptionPane.WARNING_MESSAGE);
}
JOptionPane.showMessageDialog(null, reponse, "Notification", JOptionPane.INFORMATION_MESSAGE);
}// Fin soumission
} |
Partager