Skip to content

Commit f3c65b3

Browse files
committed
feat: Optimize message box utility and add Icon support
1 parent 7967ed4 commit f3c65b3

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed
Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package com.zzhow.magicencoding.utils;
22

3+
import com.zzhow.magicencoding.MainClass;
34
import javafx.scene.control.Alert;
5+
import javafx.scene.image.Image;
6+
import javafx.stage.Stage;
7+
8+
import java.util.Objects;
49

510
/**
611
* @author ZZHow
@@ -14,25 +19,25 @@ public static void alert(Alert.AlertType type, String title, String headerText,
1419
alert.setHeaderText(headerText);
1520
alert.setContentText(contentText);
1621

22+
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
23+
Image icon = new Image(Objects.requireNonNull(MainClass.class.getResourceAsStream("/image/icon.png")));
24+
stage.getIcons().add(icon);
25+
1726
alert.showAndWait();
1827
}
1928

2029
public static void error(String headerText, String contentText) {
21-
Alert alert = new Alert(Alert.AlertType.ERROR);
22-
alert.setTitle("错误");
23-
alert.setHeaderText(headerText);
24-
alert.setContentText(contentText);
25-
26-
alert.showAndWait();
30+
alert(Alert.AlertType.ERROR,
31+
"错误",
32+
headerText,
33+
contentText);
2734
}
2835

2936
public static void success(String headerText, String contentText) {
30-
Alert alert = new Alert(Alert.AlertType.INFORMATION);
31-
alert.setTitle("成功");
32-
alert.setHeaderText(headerText);
33-
alert.setContentText(contentText);
34-
35-
alert.showAndWait();
37+
alert(Alert.AlertType.INFORMATION,
38+
"成功",
39+
headerText,
40+
contentText);
3641
}
3742

3843
}

0 commit comments

Comments
 (0)