Hola todos.
J'essaie de tester un exemple d'applet mais j'obtiens une page HTML avec une croix rouge...
Je ne sais pas d'où ca vient...
J'ai récupéré le code sur le WEB donc ca devrait fonctionner...
Maintenant, il peut s'agir d'un pb de config de ma machine ou du browser...
Sachant que l'erreur se produit sur IE et Firefox...
J'utilise 2 classes.
Le code de la 1ère classe FenPrincipale:
Le code de la 2ème classe Dialogue
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 import java.awt.*; import java.awt.event.*; import java.applet.*; public class FenPrincipale extends Applet implements ActionListener { private Dialogue monDialogue; private TextArea texteSortie; private Button bouton1; public FenPrincipale() { // Creation de la zone de texte superieure texteSortie = new TextArea(5, 40); texteSortie.setEditable(false); add("Center", texteSortie); // Creation du bouton "Ouvrir dialogue" bouton1 = new Button("Ouvrir dialogue"); bouton1.addActionListener(this); Panel monPanel = new Panel(); monPanel.setLayout(new FlowLayout()); monPanel.add(bouton1); add("South", monPanel); } // Cette methode est declenchee sur une action sur le bouton "Quitter" public void actionPerformed(ActionEvent e) { if(monDialogue == null) { monDialogue = new Dialogue(this, "Dialogue"); } monDialogue.show(); } public void ajouteText(String texte) { texteSortie.append(texte + "\n"); } public void init() { // Creation de la fenetre et affichage FenPrincipale fen = new FenPrincipale(); } }
La page test.html :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 import java.awt.*; import java.awt.event.*; public class Dialogue extends Frame implements ActionListener{ TextField champSaisie; Button boutonChangeTexte; FenPrincipale parent; public Dialogue(String titre) { this.setTitle(titre); Panel p1 = new Panel(); p1.add(new Label("Saisissez un texte :")); champSaisie = new TextField(40); p1.add(champSaisie); add("Center", p1); Panel p2 = new Panel(); p2.setLayout(new FlowLayout(FlowLayout.RIGHT)); Button b = new Button("Annuler"); b.addActionListener(this); boutonChangeTexte = new Button("Ajouter texte"); boutonChangeTexte.addActionListener(this); p2.add(b); p2.add(boutonChangeTexte); add("South", p2); pack(); } public Dialogue(FenPrincipale parent, String titre) { this(titre); this.parent = parent; } public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if((source == boutonChangeTexte) || (source == champSaisie)){ parent.ajouteText(champSaisie.getText()); } champSaisie.selectAll(); setVisible(false); } }
Gracias
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 <html> <body> <center> <h1> Voici mon applet graphique : </h1> <BR> <applet code="FenPrincipale.class" width="300" height="150" > </applet> </center> </body> </html>








Répondre avec citation



Partager