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
|
public class Entree2 extends Applet {
Image image;
public Entree2() {
// j'utilisai la première ligne pour récupérer l'image, la seconde chez moi ne passait pas. Pour la première, la photo doit être au même endroit que ta class Entree2.
//image = Toolkit.getDefaultToolkit().getImage(lePackage.Entree2.class.getResource("laPhoto.jpg"));
image = getImage(getCodeBase(), getParameter("photoe"));
try {
MediaTracker mTrack = new MediaTracker(this);
mTrack.addImage(image, 1);
mTrack.waitForAll();
}catch(Exception e) {
System.out.println("L'image n'a pas pu être chargée");
e.printStackTrace();
}
}
public void init() {
this.setSize(new Dimension(400,300));
this.setLayout(new GridBagLayout());
JLabel labelo = new JLabel("foto");
labelo.setBackground(Color.white);
labelo.setPreferredSize(new Dimension(200, 200));
labelo.setIcon(new ImageIcon(image));
this.add(labelo, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
}
} |
Partager