From f09cb54894232fe2eb6d6ea5ddebb26eaeff1d37 Mon Sep 17 00:00:00 2001 From: yushijinhun Date: Wed, 6 Jun 2018 13:52:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93JavaFX=E7=BC=BA=E5=A4=B1=E6=97=B6?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/jackhuang/hmcl/Main.java | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/Main.java b/HMCL/src/main/java/org/jackhuang/hmcl/Main.java index d604e70f9..6e8ae0916 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/Main.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/Main.java @@ -17,24 +17,42 @@ */ package org.jackhuang.hmcl; -import org.jackhuang.hmcl.util.Logging; - -import javax.swing.*; import java.io.File; +import javax.swing.JOptionPane; + public final class Main { public static void main(String[] args) { + checkJavaFX(); + checkDirectoryPath(); + Launcher.main(args); + } + + private static void checkDirectoryPath() { String currentDirectory = new File("").getAbsolutePath(); if (currentDirectory.contains("!")) { - System.err.println("Exclamation mark(!) is not allowed in the path where HMCL is in. Forcibly exit."); - // No Chinese translation because both Swing and JavaFX cannot render Chinese character properly when exclamation mark exists in the path. - String message = "Exclamation mark(!) is not allowed in the path where HMCL is in.\nThe path is " + currentDirectory; - JOptionPane.showMessageDialog(null, message, "Error", JOptionPane.ERROR_MESSAGE); - System.exit(1); - } else - Launcher.main(args); + showErrorAndExit("Exclamation mark(!) is not allowed in the path where HMCL is in.\n" + + "The path is " + currentDirectory); + } + } + + private static void checkJavaFX() { + try { + Class.forName("javafx.application.Application"); + } catch (ClassNotFoundException e) { + showErrorAndExit("JavaFX is missing.\n" + + "If you are using Java 11 or above, please downgrade to Java 8 or 10.\n" + + "If you are using OpenJDK, please ensure OpenJFX is included."); + } + } + + private static void showErrorAndExit(String message) { + System.err.println(message); + System.err.println("A fatal error has occurred, forcibly exiting."); + JOptionPane.showMessageDialog(null, message, "Error", JOptionPane.ERROR_MESSAGE); + System.exit(1); } }