Pular para o conteúdo principal

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!

Conclusion


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!

Comentários

Postagens mais visitadas deste blog

Creating custom Work Item Handler in BPM Suite/jBPM 6

Hi all! In this post I am going to share my experience creating a work item handler for BPM Suite 6.0.3 (which is very similar to jbpm as explained in a previous post ). The Hello World Work Item Handler Let's create a really simple WorkItemHandler just to print "Hello World" in the console. Of course you can implement more feature and make it receive parameters, access database, web services, etc. But in this post we will keep it simple. Really simple. First thing to do is to create a maven project for my WorkItemHandler. Here's the pom.xml of my Maven project: Notice that we are importing jbpm dependency so we can find the java interface that is used to create work item handlers. Now we can start coding. Let's create a class name HelloWorkItemHandler in package org.jugvale.jbpm, here is the simple code: Now we can build our project and go to BPM Suite to configure it so we can use this workitem. Registering the WorkItemHandler UPDATE...

Using the REST Task from jBPM 6

In this post I am going to share my experience using the BPM Suite 6 REST Task. BPM Suite  X jBPM jBPM is a JBoss community project to offer an open source and efficient BPM Suite and BPM Suite is a product created by Red Hat based on jBPM. In this post I will be using BPM Suite because I have it installed already, but what I am going to described should work for jBPM as well.   REST Task  The REST Task is used to invoke a REST resource (or perform an HTTP Request) from your Business Process. You can set the URL, HTTP Method, timeout and credentials from the Process Modeller interface and when the process gets into that task, it will generate a HTTP Request and return the response as String. It is available on the left side pallet under the "Service Tasks" tab: The Target REST Web Service The service we are going to access from our process is a really simple one, that's why it is called simple-hello-rs and it is based on JBoss helloworld-rs qu...

Simplest JavaFX ComboBox autocomplete

Based on this Brazilian community post , I've created a sample Combobox auto complete. What it basically does is: When user type with the combobox selected, it will work on a temporary string to store the typed text; Each key typed leads to the combobox to be showed and updated If backspace is type, we update the filter Each key typed shows the combo box items, when the combobox is hidden, the filter is cleaned and the tooltip is hidden:   The class code and a sample application is below. I also added the source to my personal github , sent me PR to improve it and there are a lot of things to improve, like space and accents support.