zoukankan      html  css  js  c++  java
  • JavaFX学习:Platform类

    代码示例

    public class Main extends Application {
    
        public static void main(String[] args) {
            launch(args);
        }
    
        @Override
        public void start(Stage primaryStage) throws Exception {
    
            // 空闲的时候运行
            /*
                发现并没有新开一个线程
                这个其实是一个队列,在线程空闲的时候帮你更新UI界面
             */
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    System.out.println("platform-runnable: threadName=" + Thread.currentThread().getName());
                    // 在这里可以对组件进行更新
                    System.out.println("Platform Runnable 执行");
                    int i = 1;
                    while( i< 10) {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        System.out.println("i="+i);
                        i = i + 1;
                    }
                }
            });
            System.out.println("outer threadName=" + Thread.currentThread().getName());
            System.out.println("Platform Runnable 下面");
    
            /*
                Platform.setImplicitExit(..) 将所有窗口关闭后是不是不退出虚拟机
                如果设置为false,即使程序的所有窗口都关闭了,程序依旧不会停止,需要调用 primaryStage.exit()
                如果不设置,默认就是true,所有窗口关闭了也就退出了
             */
            // // // // // // // // // // // // // // // // // // // // // // //
            /*
                Platform.isSupport(..) 是不是支持某种特性
                检查电脑平台的一些特性
             */
        }
    }
    
  • 相关阅读:
    2019-10-28-开源项目
    2018-8-10-win10-uwp-MetroLog-入门
    2018-5-20-C#-BBcode-转-Markdown
    2018-8-10-win10-UWP-序列化
    2018-2-13-win10-uwp-BadgeLogo-颜色
    2019-1-25-WPF-ListBox-的选择
    2019-1-5-Windows-的-Pen-协议
    android studio打印
    Java 基本数据类型
    FreeRTOS 任务通知模拟计数型信号量
  • 原文地址:https://www.cnblogs.com/wbyixx/p/14207721.html
Copyright © 2011-2022 走看看