File tree Expand file tree Collapse file tree
main/java/com/victorlaerte/asynctask Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010
1111# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
1212hs_err_pid *
13+
14+ .classpath
15+
16+ .project
Original file line number Diff line number Diff line change 1+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
2+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" >
3+ <modelVersion >4.0.0</modelVersion >
4+ <groupId >com.victorlaerte</groupId >
5+ <artifactId >javafx-asynctask</artifactId >
6+ <packaging >jar</packaging >
7+ <version >1.0-SNAPSHOT</version >
8+ <name >javafx-asynctask</name >
9+ <url >http://maven.apache.org</url >
10+ <dependencies >
11+ <dependency >
12+ <groupId >junit</groupId >
13+ <artifactId >junit</artifactId >
14+ <version >4.11</version >
15+ <scope >test</scope >
16+ </dependency >
17+ <dependency >
18+ <groupId >javafx</groupId >
19+ <artifactId >jfxrt</artifactId >
20+ <version >${java.version} </version >
21+ <scope >system</scope >
22+ <systemPath >${java.home} /lib/jfxrt.jar</systemPath >
23+ </dependency >
24+ </dependencies >
25+ </project >
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ package com .victorlaerte .asynctask ;
2+
3+ import javafx .application .Platform ;
4+
5+ /**
6+ *
7+ * @author Victor Oliveira
8+ */
9+ public abstract class AsyncTask {
10+
11+ private boolean daemon = true ;
12+
13+ public abstract void onPreExecute ();
14+
15+ public abstract void doInBackground ();
16+
17+ public abstract void onPostExecute ();
18+
19+ public abstract void progressCallback (Object ... params );
20+
21+ public void publishProgress (final Object ... params ) {
22+
23+ Platform .runLater (new Runnable () {
24+
25+ @ Override
26+ public void run () {
27+
28+ progressCallback (params );
29+ }
30+ });
31+ }
32+
33+ private final Thread backGroundThread = new Thread (new Runnable () {
34+
35+ @ Override
36+ public void run () {
37+
38+ doInBackground ();
39+
40+ Platform .runLater (new Runnable () {
41+
42+ @ Override
43+ public void run () {
44+
45+ onPostExecute ();
46+ }
47+ });
48+ }
49+ });
50+
51+ public void execute () {
52+
53+ Platform .runLater (new Runnable () {
54+
55+ @ Override
56+ public void run () {
57+
58+ onPreExecute ();
59+
60+ backGroundThread .setDaemon (daemon );
61+ backGroundThread .start ();
62+ }
63+ });
64+ }
65+
66+ public void setDaemon (boolean daemon ) {
67+
68+ this .daemon = daemon ;
69+ }
70+
71+ public void interrupt () {
72+
73+ this .backGroundThread .interrupt ();
74+ }
75+ }
Original file line number Diff line number Diff line change 1+ /classes /
You can’t perform that action at this time.
0 commit comments