JavaFX-Platform&Screen

1Platform常用方法有exit()、runlater()、isSupported()

exit():

1 Stage stage = new Stage();
2         Stage stage1 = new Stage();
3         Stage stage2 = new Stage();
4         stage.show();
5         stage1.show();
6         stage2.show();
7         Platform.exit ();//退出所有的界面

runLater():

System.out.println("Runnable外的线程 "+Thread.currentThread().getName());
        //Runnable外的线程 JavaFX Application Thread
        Platform.runLater(new Runnable() {
            @Override
            public void run()  {
                while(true){
                try {
                    Thread.sleep(1000);
                    System.out.println("Runnable内的线程"+Thread.currentThread().getName());
                    //Runnable内的线程JavaFX Application Thread        
         }catch (InterruptedException e){
             }
                }}
        });System.out.println("123");//先执行Runnable外的然后再执行Runnnable里的

isSupported():

 Platform.isSupported(ConditionalFeature.CONTROLS);//检测是否具有运行该控件的环境

Screen:主要的方法是查看硬件参数:

 System.out.println("实际屏幕宽度:"+Screen.getPrimary().getBounds().getWidth());
        //getPrimary()返回主屏幕
        System.out.println("实际屏幕高度:"+Screen.getPrimary().getBounds().getHeight());
        System.out.println("可见屏幕高度:"+Screen.getPrimary().getVisualBounds().getHeight());
        System.out.println("可见屏幕高度:"+Screen.getPrimary().getVisualBounds().getHeight());
        System.out.println("屏幕DPI:"+Screen.getPrimary().getDpi());
        System.out.println("屏幕列表:"+Screen.getScreens());

 补充:Platform的setImplictExit()方法用于设置当界面关闭时程序是否终止

Platform.setImplicitExit(false);//即界面关闭时程序不会终止
Platform.setImpliatExit(true);//界面关闭时程序终止

猜你喜欢

转载自www.cnblogs.com/yanquebbuyan/p/9977065.html