content: package com.summersec.attack.utils;
  
  import java.io.PrintWriter;
  import java.io.StringWriter;
  import javafx.scene.control.Alert;
  import javafx.scene.control.Label;
  import javafx.scene.control.TextArea;
  import javafx.scene.control.Alert.AlertType;
  import javafx.scene.layout.GridPane;
  import javafx.scene.layout.Priority;
  import javafx.stage.Window;
  
  public class MessageUtil {
      public MessageUtil() {
      }
  
      public static void showExceptionMessage(Exception ex, String contentText) {
          Alert alert = new Alert(AlertType.ERROR);
          alert.setTitle("错误");
          alert.setHeaderText("");
          alert.setContentText(contentText);
          StringWriter sw = new StringWriter();
          PrintWriter pw = new PrintWriter(sw);
          ex.printStackTrace(pw);
          String exceptionText = sw.toString();
          Label label = new Label("The exception stacktrace was:");
          TextArea textArea = new TextArea(exceptionText);
          textArea.setEditable(false);
          textArea.setWrapText(true);
          textArea.setMaxWidth(1.7976931348623157E308D);
          textArea.setMaxHeight(1.7976931348623157E308D);
          GridPane.setVgrow(textArea, Priority.ALWAYS);
          GridPane.setHgrow(textArea, Priority.ALWAYS);
          GridPane expContent = new GridPane();
          expContent.setMaxWidth(1.7976931348623157E308D);
          expContent.add(label, 0, 0);
          expContent.add(textArea, 0, 1);
          alert.getDialogPane().setExpandableContent(expContent);
          alert.showAndWait();
      }
  
      public static void showErrorMessage(String title, String msg) {
          Alert alert = new Alert(AlertType.ERROR);
          Window window = alert.getDialogPane().getScene().getWindow();
          window.setOnCloseRequest((event) -> {
              window.hide();
          });
          alert.setTitle(title);
          alert.setHeaderText("");
          alert.setContentText(msg);
          alert.showAndWait();
      }
  
      public static void showInfoMessage(String title, String msg) {
          Alert alert = new Alert(AlertType.INFORMATION);
          Window window = alert.getDialogPane().getScene().getWindow();
          window.setOnCloseRequest((event) -> {
              window.hide();
          });
          alert.setTitle(title);
          alert.setHeaderText("");
          alert.setContentText(msg);
          alert.showAndWait();
      }
  }
  
  
  