quinta-feira, 5 de janeiro de 2017

Quick visual effects apps development with JavaFX

Processing is a great programming language based on Java with versions for Javascript and for Python. If you don't know it, just watch a few Daniel Shiffman videos to quickly fall in love with this technology. I talked about processing and JavaFX in this post.
JavaFX is great as well and it is available in the JDK 1.8 - which means that no external libraries is required to create JavaFX applications. In this article I will show you a class I have been using to approach JavaFX to the Processing programming style.
This is not intended to have processing running on top of JavaFX. Processing is big and I would take a few days porting all methods and classes to a JavaFX app. The idea is quickly start drawing instead have to create stage, initializing, etc. Of course, the code is on github, so if you want to contribute a PR is more than welcome!
So the idea is:

  • Extend a class;
  • Override setup method to define app title, frames, width, height;
  • Override draw to animate things - bear in mind draw is called X times per second depending on value you set on frames;
  • Override event listeners methods you want;

The class to extend is DrawingApp and an example is the classing bouncing balls app. Source code:

Which results in:

Bouncing balls example

I didn't bother to get rid of the main method - if you  have any idea to avoid it, please let me know!


I liked this idea and to be honest, I wanted to have a "Processing JavaFX" thing so I would be able to use processing inside a JavaFX app, but I am happy with this class I have been using in some fun stuff I created. If you have any idea of improvement, please send me PRs on github or comment on this post!

Nenhum comentário:

Postar um comentário