java 屏幕识别_java – 检测当前屏幕边界

答案取决于屏幕的定义.您想要默认的屏幕边界还是特定的屏幕边界?

我使用以下(及其变体)来确定单个屏幕的屏幕边界

public static GraphicsDevice getGraphicsDeviceAt(Point pos) {

GraphicsDevice device = null;

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

GraphicsDevice lstGDs[] = ge.getScreenDevices();

ArrayList lstDevices = new ArrayList(lstGDs.length);

for (GraphicsDevice gd : lstGDs) {

GraphicsConfiguration gc = gd.getDefaultConfiguration();

Rectangle screenBounds = gc.getBounds();

if (screenBounds.contains(pos)) {

lstDevices.add(gd);

}

}

if (lstDevices.size() == 1) {

device = lstDevices.get(0);

}

return device;

}

public static Rectangle getScreenBoundsAt(Point pos) {

GraphicsDevice gd = getGraphicsDeviceAt(pos);

Rectangle bounds = null;

if (gd != null) {

bounds = gd.getDefaultConfiguration().getBounds();

}

return bounds;

}

基本思想是提供屏幕位置并找到与其匹配的屏幕.我有一个组件或窗口的变化,但基本上,它归结为这个.

现在,根据你的问题,听起来你想知道整个“虚拟”屏幕边界(我可能是错的),但我使用这种方法(实际上我用它来动态创建多显示器壁纸,但那是另一个题)

public static Rectangle getVirtualScreenBounds() {

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

GraphicsDevice lstGDs[] = ge.getScreenDevices();

Rectangle bounds = new Rectangle();

for (GraphicsDevice gd : lstGDs) {

bounds.add(gd.getDefaultConfiguration().getBounds());

}

return bounds;

}

基本上,它只是遍历所有屏幕设备并将那些区域添加在一起以形成“虚拟”矩形.您可以使用相同的概念将每个屏幕设备的边界作为数组返回.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值