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
| class Liste extends JPanel{
private static final long serialVersionUID = -4112048439060985533L;
BufferedImage img = new BufferedImage(512, 512, BufferedImage.OPAQUE);
FileNameExtensionFilter filter;
JButton jb = new JButton();
File[] files;
BufferedImage[] imgs;
//constructeur
public Liste() {
}
public Liste(BufferedImage img, JButton jb, BufferedImage[] imgs) {
}
public BufferedImage[] painter( File[] files) {
BufferedImage[] imgs = new BufferedImage[files.length];
for(int i = 0; i < files.length; i++) {
try{
imgs[i] = ImageIO.read( files[i] ) ;
}
catch (IOException e){
e.printStackTrace();
}
setImgs(imgs);
System.out.println("---"+imgs.length);
}
return imgs;
}
public BufferedImage[] getImgs() {
return imgs;
}
public void setImgs(BufferedImage[] imgs) {
this.imgs = imgs;
}
public void initcmp(BufferedImage img, JButton jb, File[] files) {
this.img = img;
this.jb = jb;
this.files = files;
GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0;gbc.gridy = 0;
gbc.weightx = 1;gbc.weighty = 1;
this.setLayout(new GridBagLayout());
this.add(jb, gbc);
jb.addActionListener(e->new fchzzzz() ) ;
if (files != null )
for(int i = 0; i < files.length; i++) {
try{
this.imgs[i] = ImageIO.read( files[i] ) ;
}
catch (IOException e){
e.printStackTrace();
}
}
}
public void loadImg(File[] fi ) {
for(int i = 0; i < fi.length; i++) {
try{
this.imgs[i] = ImageIO.read( fi[i] ) ;
}
catch (IOException e){
e.printStackTrace();
}
}
}
public void paintComponent(Graphics g) {
// System.out.println("****" +this.files.length); //rien
if (this.imgs !=null) {
for ( int i =0; i<this.imgs.length;i++) {
Graphics g2 = (Graphics2D)g;
g2.drawImage(this.imgs[i],0,0, this.imgs[i].getWidth(),this.imgs[i].getHeight(), null);
}
}
}
} |
Partager