Building a Calculator with Kotlin (TornadoFX, FXML, Desktop Application)

in #utopian-io7 years ago (edited)

What Will I Learn?

  • You will learn how to use TornadoFX and JavaFX to build desktop apps in Kotlin
  • You will learn about using sealed classes in Kotlin to generalize behavior
  • You will learn how FXML works on a surface level and how we can design GUIs with it

Requirements

  • The Kotlin Compiler or The Intellij/Eclipse IDE
  • A basic understanding of the JVM as a platform
  • A fair understanding of Kotlin or the Java programming language

Difficulty

  • Intermediate

Description

In this tutorial, we build a simple calculator in Kotlin using TornadoFX. TornadoFX is a kotlin wrapper library around the JavaFX framework. It allows us to use FXML for our layout and CSS to style our application. We use this simple but powerful framework to build a small calculator. We use a sealed class to generalize the basic operators for our calculator. This allows us to recursively call these operators on our input through the view. We then create a TornadoFX view by extending the view class. In this view, we add click listeners to our buttons and we also allow the users to input keyboard events. We take the input in as a string which lets us run it against a regular expression. Then if the input is a number, we convert it to a double and execute an operation on it. We then convert it back into a string and display it in the display box of the calculator. Finally, we extend the TornadoFX application class and build out our application entry point.

The source code for this project can be found here

Video Tutorial



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Thank you for taking a look at my content.

Hey @tensor I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x