More than one implementations?

Hello boys.



I’m following the tutorials on the beginner page of the Wiki.

The problem is, that HelloCollision uses:



implements ActionListener {



Where HelloAnimation uses:



implements AnimEventListener {



When I use the AnimEventListener, my models shows up correctly, and animates when the desired keys are pushed.

The problem is I can’t use the:



inputManager.addListener(this, “DoSomeThing”);, as it needs the ActionListener instead of the AnimEventListener.



Is there any way to implement both interfaces, or am I doing it wrong?

@spadeko said:
Is there any way to implement both interfaces, or am I doing it wrong?


[java]
implements ActionListener, AnimEventListener {
[/java]
1 Like

alternatively you can also create and instantiate them like:



[java]private ActionListener actionListener = new ActionListener() {

onAction() {



}

}



private AnimEventListener animEventListener = new AnimEventListener() {





}



inputManager.addListener(actionListener ("DoSomeThing"));

inputManager.addListener(animEventListener, "DoSomeThingElse");

[/java]

Nehon:



jme3test.helloworld.HelloCollision is not abstract and does not override abstract method onAction(java.lang.String,boolean,float) in com.jme3.input.controls.ActionListener



wezrule:

It’s already specified as followed:

private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("Walk") && !keyPressed) {
if (!channel.getAnimationName().equals("Walk")) {
channel.setAnim("Walk", 0.50f);
channel.setLoopMode(LoopMode.Loop);
}
}
}
};



I found out, that by changing THIS in inputManager.addListener(this, “DoTheDance”);
to ActionListener, it doesnt show the error, but I dont know if that just bypasses the error, and leaves no function. Will tell when I have tried.

I just copied the code from the original tutorial, and it works there. Time to look deeper into the code.

@spadeko said:
Nehon:

jme3test.helloworld.HelloCollision is not abstract and does not override abstract method onAction(java.lang.String,boolean,float) in com.jme3.input.controls.ActionListener

Well, yes of course you have to implement all the methods required by the interface, usually the IDE give you an hint about that.
You know, this is very basic java, and you may get into this kind of stuff a lot using JME, so I recommend you learn more about Java before getting more into JME.
JME is simple to use if you have a fair knowledge of java but it can be quite tricky if you're a java beginner.
I imagine you are eager to develop games, but go one step at a time, or the only thing you'll get from JME is frustration.