设置此图形设备的显示模式。只在 isdisplaychangesupported() 返回 true 时才允许此方法,假如支持全屏独占模式的话(即 isfullscreensupported() 返回 true),还可能要求首先使用 setfullscreenwindow(java.awt.window) 进入全屏独占模式。
该显示模式必须是由 getdisplaymodes() 返回的显示模式之一,只有一种情况例外:传递带有 displaymode.refresh_rate_unknown 刷新率的显示模式时,将从带有匹配宽度、高度和位深的可用显示模式列表中选择一个显示模式。但是,只有在位深为 displaymode.bit_depth_multi 的显示模式存在于 getdisplaymodes() 返回的列表中时,才能传递这种显示模式。
代码示例:
frame frame;
displaymode newdisplaymode;
graphicsdevice gd;
// create a frame, select desired displaymode from the list of modes
// returned by gd.getdisplaymodes() ...
if (gd.isfullscreensupported()) {
gd.setfullscreenwindow(frame);
} else {
// proceed in non-full-screen mode
frame.setsize(...);
frame.setlocation(...);
frame.setvisible(true);
}
if (gd.isdisplaychangesupported()) {
gd.setdisplaymode(newdisplaymode);
}
- 参数:
dm - 此图形设备的新显示模式。
- 抛出:
illegalargumentexception - 如果提供的 displaymode 为 null,或者在 getdisplaymodes 返回的数组中不可用
unsupportedoperationexception - 如果 isdisplaychangesupported 返回 false- 从以下版本开始:
- 1.4
- 另请参见:
getdisplaymode(),
getdisplaymodes(),
isdisplaychangesupported()