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(..) 是不是支持某种特性
                检查电脑平台的一些特性
             */
        }
    }
    
  • 相关阅读:
    每日一题力扣23 链表排序 转数组 再放入
    每日一题力扣24
    每日一题力扣206
    每日一题力扣21 神奇的递归
    每日一题力扣430
    每日一题力扣19
    每日一题力扣445 链表转数组相加两数求和
    每日一题力扣2
    【20211102】有价值的东西,需要时间
    【20211103】连岳摘抄
  • 原文地址:https://www.cnblogs.com/wbyixx/p/14207721.html
Copyright © 2011-2022 走看看