Un applet avec un bouton et une image
Bonjour,
Je débute en java et je souhaiterai faire l'applet avec un button quand on clique sur le button l'image apparait.
Merci pour votre aide
mon code est le suivant :
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
public class Applet_GUI extends Applet {
private Image photo;
private javax.swing.JLabel photoJlb;
Button afficher;
public void init()
{
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
try{
ImageIcon photo = new ImageIcon("desert.jpg");
photoJlb.setIcon(photo);
photoJlb =new JLabel(photo);
photoJlb.setSize(300, 300);
photoJlb.setLocation(300, 400);
add(photoJlb);
} catch(Exception e) {
e.printStackTrace();
}
}
};
afficher = new Button("Cliquez");
afficher.addActionListener(actionListener);
add(afficher);
}
public void paint (Graphics g) {
super.paint(g);
g.drawImage(photo, 0, 0, this);
}
}