【问题标题】:JavaFX: How to know on which system application is running on? [duplicate]JavaFX:如何知道在哪个系统上运行应用程序? [复制]
【发布时间】:2020-04-22 18:47:42
【问题描述】:

要知道哪个系统应用程序正在使用 JavaFX 运行的代码是什么?

无需进一步阅读,只需检查质量标准。

【问题讨论】:

标签: java javafx


【解决方案1】:

com.sun.javafx.PlatformUtil 类包含检查正在运行的操作系统所需的所有方法。在某些情况下不建议使用 sun 类,但以下是实用程序类提供的一些公共静态方法:

  • public static boolean isWindows()
  • public static boolean isWinVistaOrLater()
  • public static boolean isWin7OrLater()
  • public static boolean isMac()
  • public static boolean isLinux()
  • public static boolean isSolaris()
  • public static boolean isUnix()
  • public static boolean isEmbedded()
  • public static boolean isIOS()
  • public static boolean isAndroid()

【讨论】:

    【解决方案2】:

    查看下面的代码,检查 JavaFX 是否在 iOS、Android 或桌面上运行。

    /******************************************
     * Main Class
     ******************************************/    
     public class CheckPlatform {
    
       public static void main(String [] args) {
    
          if(OSPlatform.isIOS())
             System.out.println("This is an Apple Device");
          else if(OSPlatform.isAndroid())
             System.out.println("This is an Android Device");
          else if(OSPlatform.isDesktop())
             System.out.println("This is a Desktop PC");
    
       } // main()
    } // class CheckPlatform
    
    
    /******************************************
     * OSPlatform Class
     ******************************************/
    public class OSPlatform {
    
       private static String platform;
    
       static {
          platform = System.getProperty("javafx.platform","desktop").toUpperCase();
       }
    
       public static boolean isAndroid() {
          return platform.equals("ANDROID");
       } // isAndroid()
    
       public static boolean isDesktop() {
          return platform.equals("DESKTOP");
       } // isDesktop()
    
       public static boolean isIOS() {
          return platform.equals("IOS");
       } // isIOS()
    } // class OSPlatform
    

    【讨论】:

      猜你喜欢
      • 2012-06-18
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 2020-04-10
      • 2022-10-15
      • 1970-01-01
      • 2013-11-19
      • 2020-06-23
      相关资源
      最近更新 更多