-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJavafxCounter.java
More file actions
49 lines (42 loc) · 1.64 KB
/
Copy pathJavafxCounter.java
File metadata and controls
49 lines (42 loc) · 1.64 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
41
42
43
44
45
46
47
48
49
/*
* 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 javafxcounter;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
public class JavafxCounter extends Application {
private TextField tfCount;
private Button btnCount;
private int count = 0;
public void start(Stage primaryStage) {
// Allocate controls
tfCount = new TextField("0");
tfCount.setEditable(false);
btnCount = new Button("Count");
// Register event handler using Lambda Expression (JDK 8)
btnCount.setOnAction(evt -> tfCount.setText(++count + ""));
// Create a scene graph of node rooted at a FlowPane
FlowPane flow = new FlowPane();
flow.setPadding(new Insets(15, 12, 15, 12)); // top, right, bottom, left
flow.setVgap(10); // Vertical gap between nodes in pixels
flow.setHgap(10); // Horizontal gap between nodes in pixels
flow.setAlignment(Pos.CENTER); // Alignment
flow.getChildren().addAll(new Label("Count: "), tfCount, btnCount);
// Setup scene and stage
primaryStage.setScene(new Scene(flow, 400, 80));
primaryStage.setTitle("JavaFX Counter");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}