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
|
import java.awt.*;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.text.ParseException;
class search {
protected static final int parameterIndex = 0;
JFrame f;
JPanel p1;
JLabel l1;
JTextField tf1;
JButton savebtn;
rech r;
search(){
f=new JFrame("Form");
p1=new JPanel(new GridLayout(12,2,15,15));
//tp=new JTabbedPane();
l1=new JLabel("Matricule :");
l1.setHorizontalAlignment(SwingConstants.LEFT);
tf1=new JTextField(12);
savebtn=new JButton(" Rechercher ");
p1.setLayout(null);
p1.setBorder(BorderFactory.createEtchedBorder());
addComponent(p1, l1, 5,17,80,18);
addComponent(p1, tf1, 110,15,90,22);
addComponent(p1, savebtn, 90,60,100,28);
f.getContentPane().add(p1);
savebtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String value=tf1.getText();
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "eracontacttt";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db, user, pass);
PreparedStatement st=con.prepareStatement("select mat,nom,prenom,affectation,niveau_scolaire,fonction,etat,situation,date,note,img from personnels where mat=?");
Blob blob;
st.setString(1,value);
ResultSet res=st.executeQuery();
res.next();
r=new rech();
//m.form();
r.tff1.setText(tf1.getText());
r.tf2.setText(res.getString(2));
r.dis();
r.tf3.setText(res.getString(3));
r.tf4.setText(Integer.toString(res.getInt(4)));
r.tf5.setText(res.getString(5));
r.tf6.setText(res.getString(6));
r.tf71.setText(res.getString(7));
r.tf7.setText(res.getString(8));
r.tf8.setText(res.getString(9));
r.tf9.setText(res.getString(10));
blob = res.getBlob("img");
JLabel icon = new JLabel(new ImageIcon(blob.getBytes(1, (int)blob.length())));
r.photo = new JLabel();
JPanel panIcon = new JPanel();
r.p1.add(r.photo, BorderLayout.SOUTH);
r.p1.setBackground(Color.white);
r.p1.setLayout(new BorderLayout());
r.p1.add(icon);
((RootPaneContainer) r.p1).getContentPane().add(panIcon, BorderLayout.EAST);
con.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(p1,"Ce matricule n'existe pas");
}
}
});
}
/** Add Component Without a Layout Manager (Absolute Positioning) */
private void addComponent(Container container,Component c,int x,int y,int width,int height) {
c.setBounds(x,y,width,height);
container.add(c);
} //end of addComponent()
void dis()
{
f.getContentPane().add(p1);
f.setSize(320,180);
f.setVisible(true);
f.setResizable(false);
}
public static void main(String z[]){
search pro=new search();
pro.dis();
}
} |
Partager