O'Reilly logo

Introduction to JVM Languages by Vincent van der Leun

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing animation

We want a text that is entered by the user to move around the screen. To make animation possible, we'll need to keep track of some values. Therefore, let's create a class that will handle the animation. Unlike Java, Kotlin supports defining multiple classes in one source file, no matter which access modifiers are used for the classes. Add the following code just below the class block that defines the KotlinJavaFXDemo class:

    class AnimatedText {      val animatedText = Text()      val animationPane = Pane()      var directionX = 3.0      var directionY = 3.0      fun getPane(textField: TextField): Pane {          animatedText.x = 0.0          animatedText.y = 0.0          animatedText.font = Font.font("Verdana", FontWeight.BOLD, 15.0) animationPane.children.add(animatedText) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required