blob: 42597a19248443d110389cc6c3e486c627358dd7 [file] [log] [blame]
Roman Elizarovf724f6e2017-04-07 18:06:22 +03001/*
2 * Copyright 2016-2017 JetBrains s.r.o.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// This file was automatically generated from coroutines-guide-ui.md by Knit tool. Do not edit.
Roman Elizarova9687a32018-06-29 17:28:38 +030018package kotlinx.coroutines.experimental.javafx.guide.advanced01
Roman Elizarovf724f6e2017-04-07 18:06:22 +030019
20import kotlinx.coroutines.experimental.*
21import kotlinx.coroutines.experimental.channels.*
22import kotlinx.coroutines.experimental.javafx.JavaFx as UI
23import javafx.application.Application
24import javafx.event.EventHandler
25import javafx.geometry.*
26import javafx.scene.*
27import javafx.scene.input.MouseEvent
28import javafx.scene.layout.StackPane
29import javafx.scene.paint.Color
30import javafx.scene.shape.Circle
31import javafx.scene.text.Text
32import javafx.stage.Stage
33
34fun main(args: Array<String>) {
35 Application.launch(ExampleApp::class.java, *args)
36}
37
38class ExampleApp : Application() {
39 val hello = Text("Hello World!").apply {
40 fill = Color.valueOf("#C0C0C0")
41 }
42
43 val fab = Circle(20.0, Color.valueOf("#FF4081"))
44
45 val root = StackPane().apply {
46 children += hello
47 children += fab
48 StackPane.setAlignment(hello, Pos.CENTER)
49 StackPane.setAlignment(fab, Pos.BOTTOM_RIGHT)
50 StackPane.setMargin(fab, Insets(15.0))
51 }
52
53 val scene = Scene(root, 240.0, 380.0).apply {
54 fill = Color.valueOf("#303030")
55 }
56
57 override fun start(stage: Stage) {
58 stage.title = "Example"
59 stage.scene = scene
60 stage.show()
61 setup(hello, fab)
62 }
63}
64
65fun setup(hello: Text, fab: Circle) {
66 fab.onMouseClicked = EventHandler {
67 println("Before launch")
Roman Elizarov6e5f8a62017-04-19 19:15:56 +030068 launch(UI) {
Roman Elizarovf724f6e2017-04-07 18:06:22 +030069 println("Inside coroutine")
70 delay(100)
71 println("After delay")
Roman Elizarov6e5f8a62017-04-19 19:15:56 +030072 }
Roman Elizarovf724f6e2017-04-07 18:06:22 +030073 println("After launch")
74 }
75}