All Classes Namespaces Files Functions Variables
HelloWorld.java
Go to the documentation of this file.
1 package hello.button;
2 import javafx.application.Application;
3 import javafx.event.ActionEvent;
4 import javafx.event.EventHandler;
5 import javafx.geometry.Insets;
6 import javafx.scene.Scene;
7 import javafx.scene.control.Button;
8 import javafx.scene.control.Label;
9 import javafx.scene.layout.BorderPane;
10 import javafx.stage.Stage;
11 
12 /**
13  * Yksinkertainen esimerkki JavaFX ohjelmasta
14  * @author vesal
15  * @version 4.3.2016
16  */
17 public class HelloWorld extends Application {
18  @Override
19  public void start(Stage primaryStage) {
20  BorderPane root = new BorderPane();
21  Label label = new Label("Hello World!");
22  Button button = new Button("Press me!");
23  BorderPane.setMargin(button, new Insets(10));
24  // button.setOnAction( e -> label.setText("Well Done!"));
25  button.setOnAction(new EventHandler<ActionEvent>() {
26  @Override
27  public void handle(ActionEvent event) {
28  label.setText("Well Done!");
29  }
30  });
31  root.setCenter(label);
32  root.setRight(button);
33  Scene scene = new Scene(root);
34  primaryStage.setScene(scene);
35  primaryStage.show();
36  }
37 
38 
39  /** @param args ei käytössä */
40  public static void main(String[] args) {
41  launch(args);
42  }
43 }