↓を // Java primaryStage.setTitle("Hello World!"); Button btn = new Button(); btn.setText("Say 'Hello World'"); btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Hello World!"); } }); StackPane root = new StackPane(); root.getChildren().add(btn); primaryStage.setScene(new Scene(root, 300, 250)); primaryStage.show();
↓みたいに書ける。 // Kotlin primaryStage.apply { title = "Hello World!" scene = Scene(StackPane().apply { children.add(Button().apply { text = "Say 'Hello World'" onAction = EventHandler<ActionEvent> { println("Hello World!") } }) }, 300.0, 250.0) show() }
(edited)