Skip to content

Instantly share code, notes, and snippets.

@takaki
Last active July 22, 2016 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takaki/9c063dcd1b7cd3fdece57102be6848d0 to your computer and use it in GitHub Desktop.
Save takaki/9c063dcd1b7cd3fdece57102be6848d0 to your computer and use it in GitHub Desktop.
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();
}
}
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()
}
}
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")
}
}
}
}
}
}
onMouseReleased = (t:MouseEvent)=> println("Hello")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment