Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何知道分辨率屏幕宽度和高度时,我有双头或三头从一台电脑?_Java_Linux_Video_Xorg - Fatal编程技术网

Java 如何知道分辨率屏幕宽度和高度时,我有双头或三头从一台电脑?

Java 如何知道分辨率屏幕宽度和高度时,我有双头或三头从一台电脑?,java,linux,video,xorg,Java,Linux,Video,Xorg,我使用这个xrandr--output VGA1--LVDS1的左侧,从一台PC上获得了双磁头(VGA输出、DVI输出或HDMI输出)。每个都有1024x768分辨率 当我使用Java时: screen = Toolkit.getDefaultToolkit().getScreenSize(); 我得到一个巨大的两个屏幕宽度在一起。因此,我的宽度和高度都很大。 我只需要将我的应用程序放在一个屏幕上,无论是VGA还是DVI。但是使用Java我怎么知道呢 我如何使用Toolkit.getDefau

我使用这个
xrandr--output VGA1--LVDS1的左侧,从一台PC上获得了双磁头(VGA输出、DVI输出或HDMI输出)。每个都有1024x768分辨率

当我使用Java时:

screen = Toolkit.getDefaultToolkit().getScreenSize();
我得到一个巨大的两个屏幕宽度在一起。因此,我的宽度和高度都很大。 我只需要将我的应用程序放在一个屏幕上,无论是VGA还是DVI。但是使用Java我怎么知道呢

我如何使用Toolkit.getDefaultToolkit()来说明这一点

示例:(我的应用程序必须在标记Java的地方运行)

Test.java

import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;

public class Test {

  public static void main(String[] a) throws Exception {
      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      GraphicsDevice[] screenDevices = ge.getScreenDevices();
      for (int i = 0; i < screenDevices.length; i++) {
        System.out.println(screenDevices[i].getIDstring());

        DisplayMode dm = screenDevices[i].getDisplayMode();
        int screenWidth = dm.getWidth();
        int screenHeight = dm.getHeight(); 

        System.out.println("Cake: " + screenWidth + " " + screenHeight);
      }      
  }
}

Output:

:0.0
Cake: 1024 768
:0.1
Cake: 1024 768
导入java.awt.GraphicsDevice;
导入java.awt.GraphicsEnvironment;
公开课考试{
公共静态void main(字符串[]a)引发异常{
GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevices[]screenDevices=ge.getScreenDevices();
对于(int i=0;i
我想

GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()
这就是你要找的。然后,您可以通过
getDisplayMode()