Skip to content

Instantly share code, notes, and snippets.

@ngsw-taro
Created July 16, 2012 14:15
Show Gist options
  • Save ngsw-taro/3122948 to your computer and use it in GitHub Desktop.
Save ngsw-taro/3122948 to your computer and use it in GitHub Desktop.
import javafx.application.Application
import javafx.event.ActionEvent
import javafx.geometry.Pos
import javafx.scene.Scene
import javafx.scene.control.Button
import javafx.scene.control.Label
import javafx.scene.layout.VBox
import javafx.stage.Stage
import kotlinfx.*
fun main(args: Array<String>) = Application.launch(JavaFxSample.javaClass)
object JavaFxSample : Application() {
override fun start(stage: Stage?) {
var count = 0
val label = Label("$count")
val button = Button("Count")
button.setOnAction {
(event: ActionEvent) ->
label.text = "${++count}"
}
val vBox = VBox(20.0)
vBox.alignment = Pos.CENTER
vBox.children.add(label)
vBox.children.add(button)
val scene = Scene(vBox)
val style = JavaFxSample.javaClass.getResource("css/style.css")?.toExternalForm()
scene.stylesheets.add(style)
if (stage != null) {
stage.width = 400.0
stage.height = 300.0
stage.scene = scene
stage.title = "Counter"
stage.show()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment