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.
