All Projects → victorlaerte → jfx-asynctask

victorlaerte / jfx-asynctask

Licence: Apache-2.0 license
This project was created to simplify how to handle Thread tasks in Javafx, and it is based on the same idea of AsyncTask from Android.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to jfx-asynctask

Hacktober-2019
Repo for TOM members dedicated for the Hacktober fest of 2019 (6th edition), this repo is here to encourage open source learning and sharing and enhance git/github using abilities.
Stars: ✭ 16 (-51.52%)
Mutual labels:  javafx
Azkar-App
Desktop Application 💻 for Calculating Muslim prayer times 🕌 , Morning and Nights Azkar 🤲 with notification for random Azkar that pops-up in specific time.
Stars: ✭ 64 (+93.94%)
Mutual labels:  javafx
GNCarousel
Carousel based on web design
Stars: ✭ 19 (-42.42%)
Mutual labels:  javafx
MythRedisClient
🏎️使用JavaFx做的Redis客户端,资源消耗略大 200-300m,想复用核心代码做成web端,然后浏览器操作,开发起来和跑起来也快
Stars: ✭ 26 (-21.21%)
Mutual labels:  javafx
sliding-puzzle
Sliding puzzle game implemented in Scala / Scala.js / JavaFX
Stars: ✭ 25 (-24.24%)
Mutual labels:  javafx
wt4
Work tracker for JIRA
Stars: ✭ 26 (-21.21%)
Mutual labels:  javafx
dbfx
This is a free, cross platform, open source database management tool based on JavaFX and vertx SQL client.
Stars: ✭ 63 (+90.91%)
Mutual labels:  javafx
webfx
A JavaFX application transpiler. Write your Web Application in JavaFX and WebFX will transpile it in pure JS.
Stars: ✭ 210 (+536.36%)
Mutual labels:  javafx
YuMusic
A Music Player Build with JavaFX WebView, iView,RequireJS
Stars: ✭ 17 (-48.48%)
Mutual labels:  javafx
sudokufx
AR Sudoku grabber and solver using JavaCV, JavaFX and Scala
Stars: ✭ 64 (+93.94%)
Mutual labels:  javafx
jfree-fxdemos
This project contains JavaFX demo programs for the libraries created by JFree.
Stars: ✭ 38 (+15.15%)
Mutual labels:  javafx
wayland-javafx
wayland backend for javafx
Stars: ✭ 20 (-39.39%)
Mutual labels:  javafx
vic2 economy analyzer
Victoria 2 savegame economy analyzer, updated version
Stars: ✭ 44 (+33.33%)
Mutual labels:  javafx
GitFx
Gitfx Java FX application
Stars: ✭ 18 (-45.45%)
Mutual labels:  javafx
WellBehavedFX
Composable event handlers and skin scaffolding for JavaFX controls.
Stars: ✭ 52 (+57.58%)
Mutual labels:  javafx
JMemoryBuddy
No description or website provided.
Stars: ✭ 44 (+33.33%)
Mutual labels:  javafx
JFXC
Jonato JavaFX Controls - More Power for your JavaFX Gui
Stars: ✭ 42 (+27.27%)
Mutual labels:  javafx
OmniGraph
Desktop application for creating graphs and algorithm visualisation
Stars: ✭ 27 (-18.18%)
Mutual labels:  javafx
haxe-javafx-sample
Just a sample to start with Haxe + JavaFX
Stars: ✭ 12 (-63.64%)
Mutual labels:  javafx
chorus
📝 The first editor for Spigot configurations.
Stars: ✭ 133 (+303.03%)
Mutual labels:  javafx

Travis-CI Open Source Love

JavaFx AsyncTask

This class was created to simplify how to handle Thread tasks in Javafx, and it is based on the same idea of AsyncTask from Android.

AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads.

An asynchronous task is defined by a computation that runs on a background thread and whose result is published on the UI thread. An asynchronous task is defined by extending the class, and 4 steps, called onPreExecute, doInBackground, progressCallback and onPostExecute.

Optionally you have the method setDaemon to set your threads daemon, which means that if your javafx application has been closed it can still running or not. setDamon(boolean) can only be called before the thread has been started. By default the thread is set to daemon.

Use

Maven

<dependency>
    <groupId>com.victorlaerte</groupId>
    <artifactId>jfx-asynctask</artifactId>
    <version>1.0.1</version>
</dependency>

Gradle

compile group: 'com.victorlaerte', name: 'jfx-asynctask', version: '1.0.1'

Methods

onPreExecute - is used to run some rotine before the background task has started

doInBackground - is used to perform background tasks

onPostExecute - is used to run some finally rotine after background task has done

progressCallback - it will be called every time you call publishProgress to update your UI Thread as you want

publishProgress - is used to call your progressCallback and update your UI component

setDaemon - is used to set your thread daemon

execute - called to initiate all process

interrupt - is called to interrupt your thread process

Example of usage:

public class Example extends AsyncTask {
    private UIController controller;

    public Example(UIController controller) {
        this.controller = controller;
    }

    @Override
    void onPreExecute() {
    
        //This method runs on UI Thread before background task has started
        this.controller.updateProgressLabel("Starting Download")
    }

    @Override
    void doInBackground() {

    //This method runs on background thread
    
    boolean downloading = true;
    
        while (downloading){
        
            /*
            * Your download code
            */
            
            double progress = 65.5 //Your progress calculation 
            publishProgress(progress);
        }
    }

    @Override
    void onPostExecute() {

        //This method runs on UI Thread after background task has done
        this.controller.updateProgressLabel("Download is Done");

    }

    @Override
    void progressCallback(Object... params) {
    
        //This method update your UI Thread during the execution of background thread
        
        double progress = (double)params[0]
        this.controller.updateProgress(progress);
    }
}

//To call this class you just need to instatiate that doing 

Example testing = new Example(myController);
testing.execute();

Sample here

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].