public abstract class GraphicsDevice extends Object
GraphicsDevice类描述了可能在特定图形环境中可用的图形设备。
这些包括屏幕和打印机设备。
请注意,在GraphicsEnvironment的情况下可以有许多屏幕和许多打印机。
每个图形设备都有一个或多个与之相关的GraphicsConfiguration对象。
这些对象指定可以使用GraphicsDevice不同配置。
在多屏幕环境中, GraphicsConfiguration对象可用于在多个屏幕上渲染组件。 下面的代码示例演示了如何创建一个JFrame为每个对象GraphicsConfiguration在每个屏幕设备上GraphicsEnvironment :
GraphicsEnvironment ge = GraphicsEnvironment. getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); for (int j = 0; j < gs.length; j++) { GraphicsDevice gd = gs[j]; GraphicsConfiguration[] gc = gd.getConfigurations(); for (int i=0; i < gc.length; i++) { JFrame f = new JFrame(gs[j].getDefaultConfiguration()); Canvas c = new Canvas(gc[i]); Rectangle gcBounds = gc[i].getBounds(); int xoffs = gcBounds.x; int yoffs = gcBounds.y; f.getContentPane().add(c); f.setLocation((i*50)+xoffs, (i*60)+yoffs); f.show(); } }
有关全屏独占模式API的更多信息,请参阅Full-Screen Exclusive Mode API Tutorial 。
| Modifier and Type | Class and Description |
|---|---|
static class |
GraphicsDevice.WindowTranslucency
底层系统支持的半透明度。
|
| Modifier and Type | Field and Description |
|---|---|
static int |
TYPE_IMAGE_BUFFER
设备是一个图像缓冲区。
|
static int |
TYPE_PRINTER
设备是打印机。
|
static int |
TYPE_RASTER_SCREEN
设备是光栅画面。
|
| Modifier | Constructor and Description |
|---|---|
protected |
GraphicsDevice()
这是一个无法直接实例化的抽象类。
|
| Modifier and Type | Method and Description |
|---|---|
int |
getAvailableAcceleratedMemory()
此方法返回此设备上加速内存中可用的字节数。
|
GraphicsConfiguration |
getBestConfiguration(GraphicsConfigTemplate gct)
返回通过 GraphicsConfigTemplate中定义的标准的“最佳” 配置 。
|
abstract GraphicsConfiguration[] |
getConfigurations()
返回与此
GraphicsDevice所有
GraphicsConfiguration对象。
|
abstract GraphicsConfiguration |
getDefaultConfiguration()
返回默认
GraphicsConfiguration与此相关
GraphicsDevice 。
|
DisplayMode |
getDisplayMode()
返回此
GraphicsDevice的当前显示模式。
|
DisplayMode[] |
getDisplayModes()
返回此
GraphicsDevice所有显示模式。
|
Window |
getFullScreenWindow()
如果设备处于全屏模式,则返回表示全屏窗口的
Window对象。
|
abstract String |
getIDstring()
返回与此
GraphicsDevice的标识字符串。
|
abstract int |
getType()
返回此类型
GraphicsDevice 。
|
boolean |
isDisplayChangeSupported()
如果
GraphicsDevice支持低级显示更改,则返回
true 。
|
boolean |
isFullScreenSupported()
如果
GraphicsDevice支持全屏独占模式,则返回
true 。
|
boolean |
isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency translucencyKind)
返回此图形设备是否支持给定的半透明级别。
|
void |
setDisplayMode(DisplayMode dm)
设置此图形设备的显示模式。
|
void |
setFullScreenWindow(Window w)
进入全屏模式,或返回窗口模式。
|
public static final int TYPE_RASTER_SCREEN
public static final int TYPE_PRINTER
public static final int TYPE_IMAGE_BUFFER
public abstract int getType()
GraphicsDevice 。
GraphicsDevice ,可以是TYPE_RASTER_SCREEN,TYPE_PRINTER或TYPE_IMAGE_BUFFER。
TYPE_RASTER_SCREEN ,
TYPE_PRINTER ,
TYPE_IMAGE_BUFFER
public abstract String getIDstring()
GraphicsDevice的标识字符串。
一个特定的程序可能会在一个GraphicsDevice中使用多个GraphicsEnvironment 。 此方法返回一个String标识GraphicsDevice在本地GraphicsEnvironment 。 虽然没有公开的方法设置这个String ,程序员可以使用String进行调试。 在Javaâ“¢运行时环境供应商可以格式化的返回值String 。 要确定如何解释的价值String ,请联系您的Java运行时的供应商。 要从您的程序中找出供应商是谁,请使用“java.vendor”调用System类的getProperty方法。
String是这个GraphicsDevice的
GraphicsDevice 。
public abstract GraphicsConfiguration[] getConfigurations()
GraphicsDevice所有
GraphicsConfiguration对象。
GraphicsDevice一组
GraphicsConfiguration对象。
public abstract GraphicsConfiguration getDefaultConfiguration()
GraphicsConfiguration与此相关
GraphicsDevice 。
GraphicsDevice的默认
GraphicsConfiguration
GraphicsDevice 。
public GraphicsConfiguration getBestConfiguration(GraphicsConfigTemplate gct)
GraphicsConfigTemplate中定义的标准的“最佳” 配置 。
gct -
GraphicsConfigTemplate对象用于获取有效的
GraphicsConfiguration
GraphicsConfiguration即通过了指定定义的标准
GraphicsConfigTemplate 。
GraphicsConfigTemplate
public boolean isFullScreenSupported()
GraphicsDevice支持全屏独占模式,则返回true 。
如果安装了SecurityManager,它将使用AWTPermission("fullScreenExclusive")调用其checkPermission方法。
isFullScreenSupported仅在授予该权限isFullScreenSupported返回true。
AWTPermission
public void setFullScreenWindow(Window w)
isFullScreenSupported返回true 。
独家模式意味着:
Component.enableInputMethods(false)使组件成为输入法框架的非客户端。 模拟全屏模式将窗口调整到屏幕最大可能的可见区域。 然而,本地窗口系统可以修改所请求的几何相关数据,使得Window对象被放置并且以与桌面设置紧密对应的方式进行调整。
当进入全屏模式时,如果要用作全屏窗口的窗口不可见,则此方法将使其可见。 当返回到窗口模式时,它将保持可见。
当进入全屏模式时,所有的半透明效果都将重新设置为窗口。 其形状设置为null ,不透明度值设置为1.0f,背景色alpha设置为255(完全不透明)。 返回窗口模式时,这些值不会恢复。
如何在全屏模式下操作装饰窗口是未指定和依赖平台的。 因此,建议您使用setUndecorated方法关闭Frame或Dialog对象中的setUndecorated 。
当从独家全屏窗口返回窗口模式时,通过调用setDisplayMode进行的任何显示更改都将自动恢复到原始状态。
w - 用作全屏窗口的窗口;
null如果返回到窗口模式。
一些平台期望全屏窗口成为顶级组件(即Frame );
因此,最好在这里使用Frame而不是Window 。
isFullScreenSupported() ,
getFullScreenWindow() ,
setDisplayMode(java.awt.DisplayMode) ,
Component.enableInputMethods(boolean) ,
Component.setVisible(boolean) ,
Frame.setUndecorated(boolean) ,
Dialog.setUndecorated(boolean)
public Window getFullScreenWindow()
Window对象。
null如果设备不是全屏模式。
setFullScreenWindow(Window)
public boolean isDisplayChangeSupported()
GraphicsDevice支持低级显示更改,则返回true 。
在某些平台上,只有在全屏独占模式下(如isFullScreenSupported()返回true而应用程序已经使用setFullScreenWindow(java.awt.Window)已经进入全屏模式),才能允许低级显示更改。
isFullScreenSupported() ,
setDisplayMode(java.awt.DisplayMode) ,
setFullScreenWindow(java.awt.Window)
public void setDisplayMode(DisplayMode dm)
isDisplayChangeSupported()返回true ,并且可能需要首先进入全屏独占模式,使用setFullScreenWindow(java.awt.Window),只要支持全屏独占模式(即isFullScreenSupported()返回true )。
显示模式必须是getDisplayModes()返回的显示模式之一 ,但有一个例外:通过具有DisplayMode.REFRESH_RATE_UNKNOWN刷新率的显示模式将导致从匹配宽度,高度和位深度的可用显示模式列表中选择显示模式。 但是,如果在getDisplayModes()返回的列表中存在这种模式,则允许通过具有DisplayMode.BIT_DEPTH_MULTI的位深度的显示模式。
示例代码:
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返回的数组中
getDisplayModes
UnsupportedOperationException - 如果
isDisplayChangeSupported返回
false
getDisplayMode() ,
getDisplayModes() ,
isDisplayChangeSupported()
public DisplayMode getDisplayMode()
GraphicsDevice的当前显示模式。
返回的显示模式允许刷新率为DisplayMode.REFRESH_RATE_UNKNOWN(如果不确定)。
同样,返回的显示模式允许位深度为DisplayMode.BIT_DEPTH_MULTI,如果它是不确定的,或者如果支持多个位深度。
setDisplayMode(DisplayMode)
public DisplayMode[] getDisplayModes()
GraphicsDevice所有显示模式。
返回的显示模式如果不确定 ,允许刷新率为DisplayMode.REFRESH_RATE_UNKNOWN。
同样地,返回的显示模式被允许具有的比特深度DisplayMode.BIT_DEPTH_MULTI如果它是不确定的,或者如果多个位深度被支持。
public int getAvailableAcceleratedMemory()
ImageCapabilities对象的进一步查询方法可用于确定特定的VolatileImage是否已在加速内存中创建。
Image.flush() ,
ImageCapabilities.isAccelerated()
public boolean isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency translucencyKind)
translucencyKind - 一种半透明支持
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.