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
| public class AlbumPhoto extends JDialog{
private JButton image1 = new JButton((new ImageIcon(((new ImageIcon("Images\\montagne.jpg")).getImage()).getScaledInstance(120,120, java.awt.Image.SCALE_SMOOTH))));
private JButton image2 = new JButton((new ImageIcon(((new ImageIcon("Images\\newYork.jpg")).getImage()).getScaledInstance(120,120, java.awt.Image.SCALE_SMOOTH))));
private JButton tableau[] = new JButton[10];
private JPanel panCenter = new JPanel();
public AlbumPhoto(){
setSize(300,500);
setLocationRelativeTo(null);
panCenter.add(image1).setBounds(10, 10, 120, 120);
panCenter.add(image2).setBounds(10, 10, 120, 120);
add(panCenter, BorderLayout.CENTER);
tableau[0]=image1;
tableau[1]=image2;
for(int i=0; i<2; i++){ //i<2 pour le moment car je n'ai que 2 images, après ce sera: i<tableau.length
tableau[i].addActionListener(new PhotoAgrandir());
}
}
class PhotoAgrandir implements ActionListener{
public void actionPerformed(ActionEvent event) {
for(int i=0; i<tableau.length;i++){
if(event.getSource()==tableau[i]){
Photo p = new Photo();
p.setPanelPhoto ( /* ????? */);
p.setVisible(true);
}
}
}
}
public static void main(String[] args) {
AlbumPhoto a = new AlbumPhoto();
a.setVisible(true);
}
} |
Partager