• scene类和platform类javafx


    scene类电脑屏幕相关

    查看电脑屏幕宽高

    Screen primary = Screen.getPrimary();
            double dpi = primary.getDpi();
            System.out.println("当前屏幕dpi:"+dpi);
            Rectangle2D rec1 = primary.getBounds();
            Rectangle2D rec2 = primary.getVisualBounds();
            System.out.println("----全部屏幕--------");
            System.out.println("左上角x:"+rec1.getMinX()+"左上角y"+rec1.getMinY());
            System.out.println("右下角x--"+ rec1.getMaxX()+"右下角y--"+ rec1.getMaxY());
            System.out.println("宽度:"+rec1.getWidth()+"高度"+rec1.getHeight());
            System.out.println("----可以看到的屏幕--------");
            System.out.println("左上角x:"+rec2.getMinX()+"左上角y"+rec2.getMinY());
            System.out.println("右下角x--"+ rec2.getMaxX()+"右下角y--"+ rec2.getMaxY());
            System.out.println("宽度:"+rec2.getWidth()+"高度"+rec2.getHeight());
    

    给button设置图标

    scene.setCursor(Cursor.HAND);//有手,箭头啥的
    

    自定义图标

           scene.setCursor(Cursor.cursor("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg95.699pic.com%2Fxsj%2F18%2Flf%2Fv8.jpg%21%2Ffw%2F700%2Fwatermark%2Furl%2FL3hzai93YXRlcl9kZXRhaWwyLnBuZw%2Falign%2Fsoutheast&refer=http%3A%2F%2Fimg95.699pic.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1656260816&t=ecf4bde3b0f1abc7f9cc10875d8bf940"));
    
    

    从本地获取图片路径的方式

     URL url = getClass().getClassLoader().getResource("icon/icon.png");
            String oath = url.toExternalForm();
    

    完整代码

        @Override
        public void start(Stage primaryStage) throws Exception{
            Button button = new Button("按钮");
            button.setPrefHeight(100);
            button.setPrefWidth(300);
            URL url = getClass().getClassLoader().getResource("icon/icon.png");
            String path = url.toExternalForm();
            Group group = new Group(button);
            Scene scene = new Scene(group);
    
             scene.setCursor(Cursor.cursor(path));
            primaryStage.setTitle("javafx");
            primaryStage.setHeight(800);
            primaryStage.setWidth(800);
            primaryStage.setScene(scene);
            primaryStage.show();
    
        }
    

    打开网页,运行到代码就执行打开的操作

     HostServices hostServices = getHostServices();
            hostServices.showDocument("https://www.cnblogs.com/q1359720840/");
    

    platform类的使用

    Platform.runLater-队列线程按照顺序执行

       Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        System.out.println("stop()"+Thread.currentThread().getName());
                    }
                });
    

    ImplicitExit(false) 后台运行

      Platform.setImplicitExit(false);// 设置这个之后呢不执行stop方法了
            Platform.exit();//关闭 
    

    检测平台支支不支持什么效果

    Platform.isSupported(ConditionalFeature.SCENE3D)//三d效果
    
  • 相关阅读:
    python基础27 -----python进程终结篇-----IO模型
    python基础26 -----python进程及协成
    python基础25 -----python高级用法
    python基础24 -----python中的各种锁
    python基础23 -----进程和线程
    Leetcode:5. Longest Palindromic Substring
    Leetcode: 3. Longest Substring Without Repeating Characters
    4. Median of Two Sorted Arrays
    Leetcode:445. Add Two Numbers II
    Leetcode: 43. Multiply Strings
  • 原文地址:https://www.cnblogs.com/q1359720840/p/16321577.html
Copyright © 2020-2023  润新知