Aide sur recherche d'erreur
Résolu
Manz37
Messages postés
32
Statut
Membre
-
Manz37 Messages postés 32 Statut Membre -
Manz37 Messages postés 32 Statut Membre -
Bonjour,
Je tente de reproduire un programme qui affiche une main qui bouge sur 3 positions, tout en affichant "Hello World". Origine : JAVA, collection PC Poche, éditeur MicroApplication.
En voici le code source :
import java.applet.*;
import java.awt.*;
import java.net.URL;
public class hand extends Applet implements Runnable{
Font font = new Font("Helvetica", Font.BOLD, 25);
Thread signeThread=null;
Image patcheur[] = new Image[3];
int LargeurImage, HauteurImage;
int b = 0;
boolean playing = true;
AudioClip aC = null;
public void init( ) {
setBackground(Color.white);
try{
aC = getAudioClip(new URL (getDocumentBase( ), "melo1.au"));
}
catch(java.net.MalformedURLException e) {}
if(aC != null)
aC.loop( );
for(int i=0; i<3; i++) {
patcheur[i] = getImage(getDocumentBase( ), "hand"+i+".jpg" );
}
LargeurImage = 150;
HauteurImage = 150;
signeThread = new Thread(this);
signeThread.start( );
}
public void run( ) {
while(true) {
try {
signeThread.sleep(500);
} catch (InterruptedException e) {
System.out.println("interrupted");
}
repaint( );
b++;
if(b > 3)
b = 0;
}
public void stop( ) {
aC.stop( );
signeThread.stop( );
}
public boolean mouseDown(Event evt, int xPos, int yPos) {
if (xPos > 75 && xPos < 175 && yPos > 75 && yPos < 175) {
if(playing == true) {
aC.stop( );
playing = false;
}
else if(playing == false) {
aC.loop( );
playing = true;
}
}
return true;
}
public void paint(Graphics g) {
g.setFont(font);
if(b == 0) {
g.drawImage(patcheur[0], 40, 40, LargeurImage, HauteurImage, this);
g.setColor(Color.red);
g.drawString("Hello World", 10, 30);
}
if(b == 1) {
g.drawImage(patcheur[1], 40, 40, LargeurImage, HauteurImage, this);
g.setColor(Color.blue);
g.drawString("Hello World", 100, 220);
}
if(b == 2) {
g.drawImage(patcheur[2], 40, 40, LargeurImage, HauteurImage, this);
g.setColor(Color.pink);
g.drawString("Hello World", 100, 30);
}
if(b == 3) {
g.drawImage(patcheur[1], 40, 40, LargeurImage, HauteurImage, this);
g.setColor(Color.darkGrey);
g.drawString("Hello World", 10, 220);
}
}
}
Quand j'execute le compilateur et déboggeur "javac.exe" j'obtiens 14 erreurs :
- illegal start of expression
-";" expected
-identifier expected
-reached end of file while parsing
merci de votre aide.
Je tente de reproduire un programme qui affiche une main qui bouge sur 3 positions, tout en affichant "Hello World". Origine : JAVA, collection PC Poche, éditeur MicroApplication.
En voici le code source :
import java.applet.*;
import java.awt.*;
import java.net.URL;
public class hand extends Applet implements Runnable{
Font font = new Font("Helvetica", Font.BOLD, 25);
Thread signeThread=null;
Image patcheur[] = new Image[3];
int LargeurImage, HauteurImage;
int b = 0;
boolean playing = true;
AudioClip aC = null;
public void init( ) {
setBackground(Color.white);
try{
aC = getAudioClip(new URL (getDocumentBase( ), "melo1.au"));
}
catch(java.net.MalformedURLException e) {}
if(aC != null)
aC.loop( );
for(int i=0; i<3; i++) {
patcheur[i] = getImage(getDocumentBase( ), "hand"+i+".jpg" );
}
LargeurImage = 150;
HauteurImage = 150;
signeThread = new Thread(this);
signeThread.start( );
}
public void run( ) {
while(true) {
try {
signeThread.sleep(500);
} catch (InterruptedException e) {
System.out.println("interrupted");
}
repaint( );
b++;
if(b > 3)
b = 0;
}
public void stop( ) {
aC.stop( );
signeThread.stop( );
}
public boolean mouseDown(Event evt, int xPos, int yPos) {
if (xPos > 75 && xPos < 175 && yPos > 75 && yPos < 175) {
if(playing == true) {
aC.stop( );
playing = false;
}
else if(playing == false) {
aC.loop( );
playing = true;
}
}
return true;
}
public void paint(Graphics g) {
g.setFont(font);
if(b == 0) {
g.drawImage(patcheur[0], 40, 40, LargeurImage, HauteurImage, this);
g.setColor(Color.red);
g.drawString("Hello World", 10, 30);
}
if(b == 1) {
g.drawImage(patcheur[1], 40, 40, LargeurImage, HauteurImage, this);
g.setColor(Color.blue);
g.drawString("Hello World", 100, 220);
}
if(b == 2) {
g.drawImage(patcheur[2], 40, 40, LargeurImage, HauteurImage, this);
g.setColor(Color.pink);
g.drawString("Hello World", 100, 30);
}
if(b == 3) {
g.drawImage(patcheur[1], 40, 40, LargeurImage, HauteurImage, this);
g.setColor(Color.darkGrey);
g.drawString("Hello World", 10, 220);
}
}
}
Quand j'execute le compilateur et déboggeur "javac.exe" j'obtiens 14 erreurs :
- illegal start of expression
-";" expected
-identifier expected
-reached end of file while parsing
merci de votre aide.
Configuration: Windows XP Opera 9.63
9 réponses
-
Bonsoir
il te faut juste fermer une accolade juste la
repaint( );
b++;
if(b > 3)
b = 0;
}
}
bonne chance -
Merci beaucoup !
Ta réponse m'encourage à persévérer.
Maintenant il m'affiche 2 warnings :
Note: hand.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Puis quand je le compile avec -Xlint:deprecation il m'inscrit :
hand.java:50: warning: [deprecation] stop( ) in java.lang.Thread has been deprecated
signeThread.stop( ); // pointeur sous le "."
hand.java:53: warning: [deprecation] mouseDown(java.awt.Event, int, int) in java.awt.Component has been deprecated
public boolean mouseDown(Event evt, int xPos, int yPos) { // ponteur sous le "m" de "mouse"
2 warnings -
Bonjour
et bien a mon avis si ton programme marche bien pas la peine de se soucier du deprecated -
Merci encore.
J'ai réussi a compilé hand.java en hand.class mais maintenant pour l'executer il faut que je créé un fichier HTML.
Pouvez-vous m'en indiquer le code source ? -
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question -
felicitation
un code HTML pour faire quoi exactement ?
est ce que c'est une application web? -
Le code HTML serait pour executer l'applet "hand.java" précédemment compilé en "hand.class".
-
pour ne pas te mentir je n'ai jamais utilisé des applet car je debute vraiment en java
je peux creer une page html mais du html pour des applet je ne sais pas c'est quoi exactement
excuse moi.
bonne chance :) -
Bonsoir
est ce que tu peux me dire ou on insere exactement le code html ?
merci -
Bonne chance à toi aussi !
Merci pour ton aide.
Je relance le sujet sur un autre forums mieux intitulé car "aide sur recherche d'erreur" n'est plus vraiment approprié :
http://www.commentcamarche.net/forum/affich 11381798 code html pour applet graphique