-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfirmBox.java
53 lines (42 loc) · 1.12 KB
/
ConfirmBox.java
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
package emailapp;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import javafx.geometry.*;
public class ConfirmBox {
static boolean answer;
public static boolean display(String title, String message){
// Create the stage
Stage window = new Stage();
// Create the window
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle(title);
window.setMinWidth(200);
window.setMinHeight(200);
// Label
Label label = new Label();
label.setText(message);
// Buttons
Button yesButton = new Button("Yes");
yesButton.setOnAction(e -> {
answer = true;
window.close();
});
Button noButton = new Button("No");
noButton.setOnAction(e -> {
answer = false;
window.close();
});
// Create the layout
VBox layout = new VBox(10);
layout.getChildren().addAll(label, yesButton, noButton);
layout.setAlignment(Pos.CENTER);
// Create the scene
Scene scene = new Scene(layout);
window.setScene(scene);
window.showAndWait();
// Return the result
return answer;
}
}