Précédent   Forum des professionnels en informatique > Java > Développement Web en Java
Développement Web en Java Forum d'entraide sur les technologies Web de Java (JSP/Servlets, Portlets, Applets, frameworks Web, etc.) Avant de poster -> FAQ Java EE
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 03/02/2012, 17h09   #1
Invité de passage
 
Homme
Étudiant
Inscription : novembre 2011
Messages : 6
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : novembre 2011
Messages : 6
Points : 0
Points : 0
Par défaut 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);
}
}
atii13 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 01h21.


 
 
 
 
Partenaires

Hébergement Web