Newer
Older
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package org.example;
import org.example.GuiHelper.Dialog;
import org.example.GuiHelper.NumberField;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class GuiDriver extends Application {
private static Logger log = LogManager.getLogger(GuiDriver.class);
private final static int
colIndex_0 = 0,
colIndex_1 = 1;
private final Button resetBtn = new Button(Conf.get("resetButton.text"));
private final TextField nameField = new TextField();
private final NumberField ageField = new NumberField();
public static void main(String[] args) {
launch(args);
}
public GuiDriver() {
resetBtn.setDisable(true);
nameField.textProperty().addListener(event -> {
log.info("Name value '" + nameField.getText() + "' has been entered");
resetBtn.setDisable(false);
});
ageField.textProperty().addListener(event -> {
log.info("Age value '" + ageField.getText() + "' has been entered");
resetBtn.setDisable(false);
});
resetBtn.setOnAction(event -> {
nameField.setText("");
ageField.setText("");
resetBtn.setDisable(true);
Dialog.showInfo(Conf.get("infoFieldReset"));
log.info("re-setting name field");
});
}
@Override
public void start(final Stage primaryStage) {
primaryStage.setTitle("Sample GUI");
final GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));
int currentRowIndex = 0;
final Text scenetitle = new Text("Simple GUI example");
scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
grid.add(scenetitle, colIndex_0, currentRowIndex, 2, 1);
currentRowIndex++;
grid.add(new Label("Your name:"), colIndex_0, currentRowIndex);
grid.add(nameField, colIndex_1, currentRowIndex);
currentRowIndex++;
grid.add(new Label("Your age:"), colIndex_0, currentRowIndex);
grid.add(ageField, colIndex_1, currentRowIndex);
currentRowIndex++;
grid.add(resetBtn, colIndex_0, currentRowIndex);
final Scene scene = new Scene(grid, 300, 250);
primaryStage.setScene(scene);
primaryStage.show();
}
@Override
public void stop() throws Exception {
super.stop();
log.info("Terminating application");
}
}