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
| import java.awt.*;
import java.sql.*;
import java.awt.event.*;
public class ajouterAd extends Frame implements WindowListener, ActionListener {
private Panel p1,p2,p3,p4;
private Label l1,l2,l3,l4,l5,l6,l7;
private TextField t1,t2,t3,t4,t5;
private Button b1,b2;
private Choice c1,c2,c3,c4;
public ajouterAd (String N){
super(N);
p1=new Panel();
p2=new Panel();
p3=new Panel();
p4=new Panel();
l1=new Label("ID_Ad");
l2=new Label("Nom");
l3=new Label("Prenom");
l4=new Label("Adresse");
l5=new Label("Tel");
l6= new Label("Date de naissance");
l7= new Label("Sexe");
t1=new TextField(10);
t2=new TextField(10);
t3=new TextField(10);
t4=new TextField(10);
t5= new TextField(10);
c1= new Choice();
c2= new Choice();
c3= new Choice();
c4= new Choice();
c4.add("Homme");
c4.add("Femme");
for(int i=1;i<=31;i++){
String s=String.valueOf(i);
c1.add(s);
}
for(int i=1;i<=12;i++){
String s=String.valueOf(i);
c2.add(s);
}
for(int i=1900;i<=2010;i++){
String s=String.valueOf(i);
c3.add(s);
}
b1=new Button("Valider");
b2=new Button("Annuler");
p1.setLayout(new GridLayout(0,4));
//p4.setLayout(new GridLayout(0,2));
p2.setLayout(new GridLayout(0,2));
p3.setLayout(new BorderLayout());
p3.add(p2,"North");
p3.add(p1,"Center");
p3.add(p4,"South");
Font f=new Font("Arial", Font.BOLD, 13);
l1.setFont(f);
l2.setFont(f);
l3.setFont(f);
l4.setFont(f);
l5.setFont(f);
l6.setFont(f);
l7.setFont(f);
b1.setFont(f);
b2.setFont(f);
b1.setBackground(Color.GRAY);
b2.setBackground(Color.GRAY);
b1.setPreferredSize(new Dimension(150, 50));
b2.setPreferredSize(new Dimension(150, 50));
add(p3); p3.setLayout( new GridLayout(0,1));
p2.add(l1);p2.add(t1);p2.add(l2);p2.add(t2);p2.add(l3);p2.add(t3);p2.add(l4);p2.add(t4);p2.add(l5);
p2.add(t5);p2.add(l7);p2.add(c4);
p1.add(l6);
p1.add(c1);p1.add(c2);p1.add(c3);
p4.add(b1);p4.add(b2);
pack();
addWindowListener(this);
setVisible(true);
}
public static void main( String []args){
ajouterAd s= new ajouterAd ("Ajouter Adhérent");
}
public boolean action(Event i,Object o){
if(i.target==b2){
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
}
else if(i.target==b1){
String a=t1.getText();
String b=t2.getText();
String c=t3.getText();
String d=t4.getText();
String e=t5.getText();
String f=c4.getSelectedItem();
String s=c1.getSelectedItem()+"/"+c2.getSelectedItem()+"/"+c3.getSelectedItem();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection C = DriverManager.getConnection("jdbc:odbc:dd");
String requete = "INSERT INTO Adherent VALUES ('a','b','c','d','e','f','s')";
Statement St=C.createStatement();
St.executeUpdate(requete);
C.close();
}
catch( ClassNotFoundException w){
System.out.println("Erreur de chargement de driver :"+w);}
catch(SQLException w){
System.out.println("Erreur lors de la connexion :"+w);
}
}
return true;
}
public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowClosing(WindowEvent arg0) {
// TODO Auto-generated method stub
System.exit(0);
}
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
} |
Partager