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
|
public void executeRequestImage()
{
JDesktopPane panelPhoto,panelPhotoErreur;
String destination =new String("test3.jpg");
AffichageImage imageAffiche;
BufferedImage image;
JLabel messageImage=new JLabel("Cet personne n'a pas de photo") ;
File file = new File(destination);
// panel contenant les photos d'une personne
panelPhoto=new JDesktopPane();
panelPhoto.setBorder(BorderFactory.createTitledBorder("Photos"));
panelPhoto.setBounds(440,20,350, 400);
// panel dans le cas ou il ny a pas de photo
panelPhotoErreur=new JDesktopPane();
panelPhotoErreur.setBorder(BorderFactory.createTitledBorder("Photos"));
panelPhotoErreur.setBounds(440,20,350, 400);
this.requestImage=new String("select * from tableBlob where ID_PERSONNE="+Integer.parseInt(textId.getText()));
try {
stmtImage=connec.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
this.rsetImage=stmtImage.executeQuery(requestImage);
nbreImage=0;
while(rsetImage.next())
{
nbreImage++;
}
System.out.println("nbre d'images : "+nbreImage);
if(nbreImage==0)
{
//rend invisible le panel photo
panelPhoto.setVisible(false);
//efface le contenu du panel photo erreur
panelPhotoErreur.removeAll();
messageImage.setBounds(100,175, 200, 50);
panelPhotoErreur.add(messageImage);
//ajout du panel contenant les photos erreur
panelPrincipale.add(panelPhotoErreur);
}
else
{
//efface le contenu du panel photo
panelPhoto.removeAll();
//rend invisible le panel photoerreur
panelPhotoErreur.setVisible(false);
//on recupere la premiere image
rsetImage.first();
blob= rsetImage.getBlob("image_tableBlob");
//lecture du blob et écriture sur le disque
image = ImageIO.read(blob.getBinaryStream());
FileOutputStream stream = new FileOutputStream(file);
ImageIO.write(image,"jpg",stream);
imageAffiche = new AffichageImage("test3.jpg",panelPhoto);
panelPhoto.add(imageAffiche);
//ajout du panel contenant les photos
panelPrincipale.add(panelPhoto);
}
}
catch (SQLException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
catch (IOException eO)
{
// TODO Auto-generated catch block
eO.printStackTrace();
}
} |
Partager