Java 怎么通过graphicsdevice合并所有屏幕

2019年8月21日22:01:19 评论 20

1.简介

Java 怎么通过graphicsdevice合并所有屏幕?——请看下文。

2.代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(mergeAllScreens());
    }

    
    public static Rectangle mergeAllScreens() {
        Rectangle virtualBounds = new Rectangle();
        final GraphicsEnvironment ge = GraphicsEnvironment
                .getLocalGraphicsEnvironment();
        for (final GraphicsDevice gd : ge.getScreenDevices()) {
            for (final GraphicsConfiguration element : gd
                    .getConfigurations()) {
                virtualBounds = virtualBounds.union(element.getBounds());
            }
        }
        return virtualBounds;
    }
}

 

3.总结

示例代码演示了 Java 怎么通过graphicsdevice合并所有屏幕,具体步骤参见示例代码。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: