-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJavaFXHello.java
More file actions
40 lines (34 loc) · 1.5 KB
/
Copy pathJavaFXHello.java
File metadata and controls
40 lines (34 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javafxhello;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class JavaFXHello extends Application {
private Button btnHello; // Declare a "Button" control
@Override
public void start(Stage primaryStage) {
// Construct the "Button" and attach an "EventHandler"
btnHello = new Button();
btnHello.setText("Say Hello");
// Using JDK 8 Lambda Expression to construct an EventHandler<ActionEvent>
btnHello.setOnAction(evt -> System.out.println("Hello World!"));
// Construct a scene graph of nodes
StackPane root = new StackPane(); // The root of scene graph is a layout node
root.getChildren().add(btnHello); // The root node adds Button as a child
Scene scene = new Scene(root, 300, 100); // Construct a scene given the root of scene graph
primaryStage.setScene(scene); // The stage sets scene
primaryStage.setTitle("Hello"); // Set window's title
primaryStage.show(); // Set visible (show it)
}
public static void main(String[] args) {
launch(args);
}
}