LoginSignup
2
2

More than 5 years have passed since last update.

ScalaでJavaFXのHello Worldのテンプレート

Last updated at Posted at 2016-05-26

よく使うのでここに健忘録。

JavaFXサンプル・アプリケーション・スタート・ガイド の Hello WorldをScalaにすると以下の実装になる。

import javafx.application.Application
import javafx.event.{ActionEvent, EventHandler}
import javafx.scene.Scene
import javafx.scene.control.Button
import javafx.scene.layout.StackPane
import javafx.stage.Stage

object Main extends App {
  Application.launch(classOf[Main], args: _*)
}

class Main extends Application {
  override def start(primaryStage: Stage): Unit = {
    val btn = new Button()
    btn.setText("Say 'Hello World'")

    btn.setOnAction(new EventHandler[ActionEvent] {
      override def handle(event: ActionEvent): Unit = {
        println("Hello")
      }
    })

    val root = new StackPane()
    root.getChildren.add(btn)

    val scene = new Scene(root, 300, 250)
    primaryStage.setTitle("Hello World!!")
    primaryStage.setScene(scene)
    primaryStage.show()
  }
}

実行すると、以下の様なダイアログが表示される。

スクリーンショット 2016-05-26 13.29.42.png

あとは JavaFX2.2のAPIの日本語訳 を見ながらゴリゴリ書いていく。なぜかGoogleの検索で一番にヒットしない。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2