Skip to content

Commit 9f2567c

Browse files
author
Dominik Liebler
committed
step2
1 parent 3979e99 commit 9f2567c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/main/kotlin/Main.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import javafx.scene.Scene
44
import javafx.scene.control.Label
55
import javafx.scene.layout.Pane
66
import javafx.stage.Stage
7-
import kotlinx.coroutines.Dispatchers
8-
import kotlinx.coroutines.GlobalScope
9-
import kotlinx.coroutines.delay
10-
import kotlinx.coroutines.launch
7+
import kotlinx.coroutines.*
8+
import kotlinx.coroutines.javafx.JavaFx
9+
import kotlin.coroutines.CoroutineContext
1110

1211
class MillisElapsedCounter(private val observer: Observer) {
1312
fun start() {
@@ -27,7 +26,10 @@ class MillisElapsedCounter(private val observer: Observer) {
2726
}
2827
}
2928

30-
class MyApp : Application(), MillisElapsedCounter.Observer {
29+
class MyApp : Application(), MillisElapsedCounter.Observer, CoroutineScope {
30+
override val coroutineContext: CoroutineContext
31+
get() = Dispatchers.JavaFx
32+
3133
private val button = Label().also { it.text = "waiting for 0s" }
3234

3335
override fun start(primaryStage: Stage?) {
@@ -42,7 +44,9 @@ class MyApp : Application(), MillisElapsedCounter.Observer {
4244
}
4345

4446
override fun notify(millisElapsed: Int) {
45-
button.text = "waiting for ${millisElapsed / 1000}s"
47+
launch {
48+
button.text = "waiting for ${millisElapsed / 1000}s"
49+
}
4650
}
4751
}
4852

0 commit comments

Comments
 (0)