-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlertBox.java
40 lines (32 loc) · 1.12 KB
/
AlertBox.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
/**
* AlertBox
* Makes a lil box which you can set the title, little message inside and
*/
package uk.ac.soton.comp1206;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
public class AlertBox {
//Show the Window
public static void display(String title, String message){
Stage window = new Stage();
//Block events to other windows
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle(title);
window.setMinWidth(256);
Label label = new Label(message);
Button closeButton = new Button("Close");
closeButton.setOnAction(e -> window.close());
VBox layout = new VBox(10);
layout.getChildren().addAll(label, closeButton);
layout.setAlignment(Pos.CENTER);
//Display window, wait for it to closed before returning
Scene scene = new Scene(layout);
window.setScene(scene);
window.showAndWait();
}
}