Bonsoir,

Voici mon nouveau problème, j'essaye d'implémenter le SVGEventListener en m'appuyant sur cette démo.

Voici mon code :

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.io.IOException;
import java.io.InputStream;
 
import javax.microedition.lcdui.*;
import javax.microedition.m2g.SVGAnimator;
import javax.microedition.m2g.SVGEventListener;
import javax.microedition.m2g.SVGImage;
import javax.microedition.m2g.ScalableGraphics;
import javax.microedition.midlet.*;
 
import org.w3c.dom.Document;
import org.w3c.dom.svg.*;
 
 
public class MyApp extends MIDlet implements CommandListener, SVGEventListener{
    private final Command start=new Command("Start",Command.OK,2);
    private final Command exit=new Command("Exit",Command.EXIT,1);
	private SvgCanvas canvas;
	private SVGImage svgImage;
	private Document doc;
	private SVGElement logo;
    public MyApp(){
    }
    public void startApp(){
		try{
			svgImage=(SVGImage)SVGImage.createImage((InputStream)getClass().getResourceAsStream("/logo.svg"),null);
			doc=svgImage.getDocument();
			logo=(SVGElement)doc.getElementById("logo");
			logo.setTrait("fill","red");
			canvas=new SvgCanvas(svgImage);
			canvas.addCommand(start);
			canvas.addCommand(exit);
			canvas.setCommandListener(this);
		}
		catch(IOException e){
			e.printStackTrace();
		}
        Display.getDisplay(this).setCurrent(canvas);
    }
    public void pauseApp(){
    }
    public void destroyApp(boolean unconditional){
    }
    public void commandAction(Command c,Displayable d){
        if (c==exit){
            destroyApp(false);
            notifyDestroyed();
        }
    }
}
class SvgCanvas extends Canvas{
    protected SVGImage svgImage;
    protected ScalableGraphics sg=ScalableGraphics.createInstance();
    protected SvgCanvas(final SVGImage svgImage){
        this.svgImage=svgImage;
    }
    public void paint(Graphics g){
		sg.setRenderingQuality(2);
        g.setColor(219,238,255);
        g.fillRect(0,0,getWidth(),getHeight());
        sg.bindTarget(g);
        svgImage.setViewportWidth(getWidth());
        svgImage.setViewportHeight(getHeight());
        sg.render(0,0,svgImage);
        sg.releaseTarget();
    }
}


Le problème est que lorsque je l'implémente tel que dans la démo, j'ai le message suivant:

MyApp is not abstract and does not override abstract method sizeChanged(int,int) in javax.microedition.m2g.SVGEventListener
public class MyApp extends MIDlet implements CommandListener, SVGEventListener{

Ce que je ne comprends pas, c'est pourquoi cela génère une erreur chez moi alors que selon la même méthode, dans la démo, cela n'en génère pas.

Pourriez-vous m'expliquer, svp?