B4J Question This Inline code is working properly

Vitor

Member
This Inline code is working properly, It log's "END ANIMATION" when animation finish.
How do I set a Sub in my application for this Event ?
Many Thanks.



#if java
import javafx.scene.control.*;
import javafx.scene.image.*;
import javafx.scene.transform.Rotate;
import javafx.animation.*;
import javafx.util.Duration;





private static Rotate rotator = new Rotate();


public static void setRotatePoint(ImageView iv,Double angle,Double x,Double y){
// clear transforms
iv.getTransforms().clear();
//rotation
rotator = new Rotate(angle,x,y);
// add rotation to the imageview
iv.getTransforms().add(rotator);
}



public static void animeRotation(ImageView card){
Animation Anime = animeRotator(card);
Anime.play();
}


private static Animation animeRotator(ImageView card) {
RotateTransition Anime = new RotateTransition(Duration.millis(5000), card);
Anime.setAxis(Rotate.X_AXIS);
Anime.setFromAngle(0);
Anime.setToAngle(90);
Anime.setInterpolator(Interpolator.LINEAR);
Anime.setCycleCount(1);

Anime.setOnFinished(event -> {
//this code runs when the animation is complete
System.out.println("END ANIMATION");
});
return new ParallelTransition(card, Anime);
}
#end if
 
Last edited:
Solution
Many thanks teddybear nice and simple as clear water.
The struggling was here
Compiling generated Java code. Error
src\b4j\example\main.java:319: error: non-static variable this cannot be referenced from a static context
ba.raiseEventFromUI(this, EventName.toLowerCase(BA.cul));

java:
public static void animeRotation(ImageView card){
       Animation Anime = animeRotator(card);
       Anime.setOnFinished(event -> {
        //this code runs when the animation is complete
        //System.out.println("END ANIMATION");
        String EventName="Animation_Finished";
        ba.raiseEventFromUI(this, EventName.toLowerCase(BA.cul));
    });

       Anime.play();
    }
The log has told you that non-static variable this...

teddybear

Well-Known Member
Licensed User
1.Please surround the code you want to post with CODE</> tags, it looks like this.
Java:
#if java
import javafx.scene.control.*;
import javafx.scene.image.*;
import javafx.scene.transform.Rotate;
import javafx.animation.*;
import javafx.util.Duration;
...
2. b4j sub
B4X:
Sub EndAnimation(s As String)
    Log("b4j:"&s)
End Sub
inline java Anime.setOnFinished
Java:
...
Anime.setOnFinished(event -> {
    //this code runs when the animation is complete
    System.out.println("END ANIMATION");
    ba.raiseEvent(null, "endanimation", "END ANIMATION");  //Callback b4j Event
});
...
 
Last edited:
Upvote 0

Vitor

Member
1.Please surround the code you want to post with CODE</> tags, it looks like this.
Java:
#if java
import javafx.scene.control.*;
import javafx.scene.image.*;
import javafx.scene.transform.Rotate;
import javafx.animation.*;
import javafx.util.Duration;
...
2. b4j sub
B4X:
Sub EndAnimation(s As String)
    Log("b4j:"&s)
End Sub
inline java Anime.setOnFinished
Java:
...
Anime.setOnFinished(event -> {
    //this code runs when the animation is complete
    System.out.println("END ANIMATION");
    ba.raiseEvent(null, "endanimation", "END ANIMATION");  //Callback b4j Event
});
...
 
Upvote 0

Vitor

Member
Many thanks teddybear nice and simple as clear water.
The struggling was here
Compiling generated Java code. Error
src\b4j\example\main.java:319: error: non-static variable this cannot be referenced from a static context
ba.raiseEventFromUI(this, EventName.toLowerCase(BA.cul));

java:
public static void animeRotation(ImageView card){
       Animation Anime = animeRotator(card);
       Anime.setOnFinished(event -> {
        //this code runs when the animation is complete
        //System.out.println("END ANIMATION");
        String EventName="Animation_Finished";
        ba.raiseEventFromUI(this, EventName.toLowerCase(BA.cul));
    });

       Anime.play();  
    }
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Many thanks teddybear nice and simple as clear water.
The struggling was here
Compiling generated Java code. Error
src\b4j\example\main.java:319: error: non-static variable this cannot be referenced from a static context
ba.raiseEventFromUI(this, EventName.toLowerCase(BA.cul));

java:
public static void animeRotation(ImageView card){
       Animation Anime = animeRotator(card);
       Anime.setOnFinished(event -> {
        //this code runs when the animation is complete
        //System.out.println("END ANIMATION");
        String EventName="Animation_Finished";
        ba.raiseEventFromUI(this, EventName.toLowerCase(BA.cul));
    });

       Anime.play();
    }
The log has told you that non-static variable this cannot be referenced from a static context
Try this
B4X:
 ba.raiseEventFromUI(null, EventName.toLowerCase(BA.cul));
 
Upvote 0
Solution
Top