Screen display size

前端 未结 7 992
长情又很酷
长情又很酷 2021-01-19 03:50

Hi I\'m writing a graphics program and I\'ve been searching for a way to get the physical size of the screen being used. I can get the size of the screen in pixels and also

7条回答
  •  一生所求
    2021-01-19 04:13

    You can try to use:

    Dimension screen = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    int pixelPerInch= java.awt.Toolkit.getDefaultToolkit().getScreenResolution();
    double height=screen.getHeight()/pixelPerInch;
    double width=screen.getWidth()/pixelPerInch;
    double x=Math.pow(height,2);
    double y=Math.pow(width,2);
    double diagonal= Math.sqrt(x+y);
    

    The "diagonal" value is in inches.

提交回复
热议问题