Skip to content

Commit

Permalink
feat: Optimize message box utility and add Icon support
Browse files Browse the repository at this point in the history
  • Loading branch information
ZZHow1024 committed Sep 6, 2024
1 parent 7967ed4 commit f3c65b3
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/main/java/com/zzhow/magicencoding/utils/MessageBox.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.zzhow.magicencoding.utils;

import com.zzhow.magicencoding.MainClass;
import javafx.scene.control.Alert;
import javafx.scene.image.Image;
import javafx.stage.Stage;

import java.util.Objects;

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

Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
Image icon = new Image(Objects.requireNonNull(MainClass.class.getResourceAsStream("/image/icon.png")));
stage.getIcons().add(icon);

alert.showAndWait();
}

public static void error(String headerText, String contentText) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("错误");
alert.setHeaderText(headerText);
alert.setContentText(contentText);

alert.showAndWait();
alert(Alert.AlertType.ERROR,
"错误",
headerText,
contentText);
}

public static void success(String headerText, String contentText) {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("成功");
alert.setHeaderText(headerText);
alert.setContentText(contentText);

alert.showAndWait();
alert(Alert.AlertType.INFORMATION,
"成功",
headerText,
contentText);
}

}

0 comments on commit f3c65b3

Please sign in to comment.