ActionListener Problem!

I created a ActionListenerClass like this one:



[java]public class speedListener implements ActionListener {



private Shuttle shuttle= new Shuttle();

private float speed;



public void onAction(String name, boolean isPressed, float tpf) {



speed=shuttle.gettrackspeed();

if (name.equals("SpeedUP") && !isPressed) {



if (shuttle.gettrackspeed() > 5f) {

shuttle.set_trackspeed(0.2f);



}

speed=shuttle.gettrackspeed()+0.2f;

shuttle.set_trackspeed(speed);

System.out.println(shuttle.gettrackspeed()); // This works fine

}

}[/java]



in my Shuttle-Class (my MainClass) :



Here i am adding my listener:

[java] private void setSpeedListener() {

inputManager.addMapping("SpeedUP",

new KeyTrigger(KeyInput.KEY_UP));

inputManager.addListener(new speedListener(), "SpeedUP");

}[/java]



This is my simpleUpdate Method. Here I get the wrong value:



[java]public void simpleUpdate(float tpf) {



motionTrack.setSpeed(trackspeed);

System.out.println("Test:"+trackspeed); //doesnt works default value



}[/java]



This is my setter: Here i get the right value

[java] public void set_trackspeed(float setter){

this.trackspeed=setter;

System.out.println(trackspeed); // This works fine

}[/java]

@barak said:
[java][/java]public class speedListener implements ActionListener {

private Shuttle shuttle= new Shuttle();


You say Shuttle is your main class? Why are you creating another one inside the listener? Obviously the state won't be shared between this second application and your main one.
1 Like

that was it! Thanks!