forked from hacker85/JavaLessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadsLesson.java
More file actions
42 lines (36 loc) · 1.13 KB
/
ThreadsLesson.java
File metadata and controls
42 lines (36 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package fx;
import javafx.application.Application;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.concurrent.WorkerStateEvent;
import javafx.event.EventHandler;
import javafx.stage.Stage;
import java.io.IOException;
import java.net.MalformedURLException;
public class ThreadsLesson extends Application {
@Override
public void start(Stage stage) throws Exception {
MyService service = new MyService();
service.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
@Override
public void handle(WorkerStateEvent t) {
System.out.println("done:" + t.getSource().getValue());
}
});
service.start();
}
public static void main(String[] args) {
launch();
}
private static class MyService extends Service<String> {
@Override
protected Task<String> createTask() {
return new Task<String>() {
@Override
protected String call() throws IOException, MalformedURLException {
return "hello";
}
};
}
}
}