java 屏幕分辨率_如何在java中获得屏幕分辨率?

这三个函数以Java格式返回屏幕大小 . 此代码考虑了多显示器设置和任务栏 . 包含的函数是: getScreenInsets() , getScreenWorkingArea() 和 getScreenTotalArea() .

码:

/**

* getScreenInsets, This returns the insets of the screen, which are defined by any task bars

* that have been set up by the user. This function accounts for multi-monitor setups. If a

* window is supplied, then the the monitor that contains the window will be used. If a window

* is not supplied, then the primary monitor will be used.

*/

static public Insets getScreenInsets(Window windowOrNull) {

Insets insets;

if (windowOrNull == null) {

insets = Toolkit.getDefaultToolkit().getScreenInsets(GraphicsEnvironment

.getLocalGraphicsEnvironment().getDefaultScreenDevice()

.getDefaultConfiguration());

} else {

insets = windowOrNull.getToolkit().getScreenInsets(

windowOrNull.getGraphicsConfiguration());

}

return insets;

}

/**

* getScreenWorkingArea, This returns the working area of the screen. (The working area excludes

* any task bars.) This function accounts for multi-monitor setups. If a window is supplied,

* then the the monitor that contains the window will be used. If a window is not supplied, then

* the primary monitor will be used.

*/

static public Rectangle getScreenWorkingArea(Window windowOrNull) {

Insets insets;

Rectangle bounds;

if (windowOrNull == null) {

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

insets = Toolkit.getDefaultToolkit().getScreenInsets(ge.getDefaultScreenDevice()

.getDefaultConfiguration());

bounds = ge.getDefaultScreenDevice().getDefaultConfiguration().getBounds();

} else {

GraphicsConfiguration gc = windowOrNull.getGraphicsConfiguration();

insets = windowOrNull.getToolkit().getScreenInsets(gc);

bounds = gc.getBounds();

}

bounds.x += insets.left;

bounds.y += insets.top;

bounds.width -= (insets.left + insets.right);

bounds.height -= (insets.top + insets.bottom);

return bounds;

}

/**

* getScreenTotalArea, This returns the total area of the screen. (The total area includes any

* task bars.) This function accounts for multi-monitor setups. If a window is supplied, then

* the the monitor that contains the window will be used. If a window is not supplied, then the

* primary monitor will be used.

*/

static public Rectangle getScreenTotalArea(Window windowOrNull) {

Rectangle bounds;

if (windowOrNull == null) {

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

bounds = ge.getDefaultScreenDevice().getDefaultConfiguration().getBounds();

} else {

GraphicsConfiguration gc = windowOrNull.getGraphicsConfiguration();

bounds = gc.getBounds();

}

return bounds;

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值