Last active
July 22, 2016 03:40
-
-
Save takaki/9c063dcd1b7cd3fdece57102be6848d0 to your computer and use it in GitHub Desktop.
ScalaFXを使ってみた ref: http://qiita.com/takaki@github/items/6baab46a872870a67ba0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.application.Application; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Button; | |
import javafx.scene.layout.VBox; | |
import javafx.stage.Stage; | |
public class FxButton extends Application { | |
public static void main(final String[] args) { | |
Application.launch(args); | |
} | |
@Override | |
public void start(final Stage stage) throws Exception { | |
Button button = new Button("Hello World"); | |
button.setOnMouseClicked(ev -> System.out.println("Hello World")); | |
VBox vbox = new VBox(button); | |
final Scene scene = new Scene(vbox); | |
stage.setScene(scene); | |
stage.setTitle("Hello"); | |
stage.show(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.application.Application | |
import javafx.event.EventHandler | |
import javafx.scene.Scene | |
import javafx.scene.control.Button | |
import javafx.scene.input.MouseEvent | |
import javafx.scene.layout.VBox | |
import javafx.stage.Stage | |
object JavaFxHello { | |
def main(args: Array[String]) { | |
val hello = new JavaFxHello | |
hello.run(args) | |
// Application.launch(classOf[JavaFxHello], args: _*) // ここで呼ぶときはこちらを使う | |
// Application.launch(args: _*) // NG | |
} | |
} | |
class JavaFxHello extends Application { | |
def run(args: Array[String]) { | |
Application.launch(args: _*) | |
} | |
override def start(stage: Stage) { | |
val button: Button = new Button("Hello World") | |
val handler = new EventHandler[MouseEvent] { | |
override def handle(t: MouseEvent) { | |
println("Hello!") | |
} | |
} | |
button.setOnMouseClicked(handler) | |
val vbox: VBox = new VBox(button) | |
val scene: Scene = new Scene(vbox) | |
stage.setScene(scene) | |
stage.setTitle("Hello") | |
stage.show() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example.lambda | |
import scalafx.Includes._ | |
import scalafx.application.JFXApp | |
import scalafx.application.JFXApp.PrimaryStage | |
import scalafx.scene.Scene | |
import scalafx.scene.control.Button | |
import scalafx.scene.layout.VBox | |
object ScalaFxHello extends JFXApp { | |
stage = new PrimaryStage { | |
title = "Hello" | |
scene = new Scene { | |
root = new VBox { | |
children = new Button("Hello Button") { | |
onMouseClicked = handle { | |
println("hello") | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onMouseReleased = (t:MouseEvent)=> println("Hello") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment