blob: e032ba416d44c70c3ec0b8f8bc97a08cc66b89fd [file] [log] [blame]
Roman Elizarovf724f6e2017-04-07 18:06:22 +03001/*
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03002 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Roman Elizarovf724f6e2017-04-07 18:06:22 +03003 */
4
5// This file was automatically generated from coroutines-guide-ui.md by Knit tool. Do not edit.
Roman Elizarova9687a32018-06-29 17:28:38 +03006package kotlinx.coroutines.experimental.javafx.guide.advanced02
Roman Elizarovf724f6e2017-04-07 18:06:22 +03007
8import kotlinx.coroutines.experimental.*
9import kotlinx.coroutines.experimental.channels.*
10import kotlinx.coroutines.experimental.javafx.JavaFx as UI
11import javafx.application.Application
12import javafx.event.EventHandler
13import javafx.geometry.*
14import javafx.scene.*
15import javafx.scene.input.MouseEvent
16import javafx.scene.layout.StackPane
17import javafx.scene.paint.Color
18import javafx.scene.shape.Circle
19import javafx.scene.text.Text
20import javafx.stage.Stage
21
22fun main(args: Array<String>) {
23 Application.launch(ExampleApp::class.java, *args)
24}
25
26class ExampleApp : Application() {
27 val hello = Text("Hello World!").apply {
28 fill = Color.valueOf("#C0C0C0")
29 }
30
31 val fab = Circle(20.0, Color.valueOf("#FF4081"))
32
33 val root = StackPane().apply {
34 children += hello
35 children += fab
36 StackPane.setAlignment(hello, Pos.CENTER)
37 StackPane.setAlignment(fab, Pos.BOTTOM_RIGHT)
38 StackPane.setMargin(fab, Insets(15.0))
39 }
40
41 val scene = Scene(root, 240.0, 380.0).apply {
42 fill = Color.valueOf("#303030")
43 }
44
45 override fun start(stage: Stage) {
46 stage.title = "Example"
47 stage.scene = scene
48 stage.show()
49 setup(hello, fab)
50 }
51}
52
53fun setup(hello: Text, fab: Circle) {
54 fab.onMouseClicked = EventHandler {
55 println("Before launch")
56 launch(UI, CoroutineStart.UNDISPATCHED) { // <--- Notice this change
57 println("Inside coroutine")
58 delay(100) // <--- And this is where coroutine suspends
59 println("After delay")
60 }
61 println("After launch")
62 }
63}