本文整理汇总了Java中java.awt.GraphicsEnvironment.getDefaultScreenDevice方法的典型用法代码示例。如果您正苦于以下问题:Java GraphicsEnvironment.getDefaultScreenDevice方法的具体用法?Java GraphicsEnvironment.getDefaultScreenDevice怎么用?Java GraphicsEnvironment.getDefaultScreenDevice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.GraphicsEnvironment
的用法示例。
在下文中一共展示了GraphicsEnvironment.getDefaultScreenDevice方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
public static void main(final String[] args) {
final GraphicsEnvironment lge = getLocalGraphicsEnvironment();
final GraphicsDevice dev = lge.getDefaultScreenDevice();
final GraphicsConfiguration config = dev.getDefaultConfiguration();
test(config.createCompatibleImage(10, 10).getGraphics());
test(config.createCompatibleImage(10, 10, OPAQUE).getGraphics());
test(config.createCompatibleImage(10, 10, BITMASK).getGraphics());
test(config.createCompatibleImage(10, 10, TRANSLUCENT).getGraphics());
test(new BufferedImage(10, 10, TYPE_INT_ARGB).getGraphics());
final Window frame = new Frame();
frame.pack();
try {
test(frame.getGraphics());
test(frame.createImage(10, 10).getGraphics());
} finally {
frame.dispose();
}
}
示例2: hasAppleRetinaDisplay
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
/**
* hack from
* https://bulenkov.com/2013/06/23/retina-support-in-oracle-jdk-1-7/ used to
* multiply mouse coordinates by two in case of retina display; see
* http://forum.lwjgl.org/index.php?topic=5084.0
*
* @return true if running on platform with retina display. Value is cached
* in VM to avoid runtime cost penalty of multiple calls.
*/
public static boolean hasAppleRetinaDisplay() {
if (checkedRetinaDisplay) {
return hasRetinaDisplayTrue;
}
checkedRetinaDisplay = true;
//other OS and JVM specific checks...
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice device = env.getDefaultScreenDevice();
try {
Field field = device.getClass().getDeclaredField("scale");
if (field != null) {
field.setAccessible(true);
Object scale = field.get(device);
if (scale instanceof Integer && ((Integer) scale).intValue() == 2) {
hasRetinaDisplayTrue = true;
}
}
} catch (Exception ignore) {
}
//...
return hasRetinaDisplayTrue;
}
示例3: iconToImage
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
public static Image iconToImage(Icon icon) {
if (icon instanceof ImageIcon) {
return ((ImageIcon) icon).getImage();
} else {
int w = icon.getIconWidth();
int h = icon.getIconHeight();
GraphicsEnvironment ge
= GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
BufferedImage image = gc.createCompatibleImage(w, h);
Graphics2D g = image.createGraphics();
icon.paintIcon(null, g, 0, 0);
g.dispose();
return image;
}
}
示例4: main
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
public static void main(String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice graphicDevice = ge.getDefaultScreenDevice();
if (!graphicDevice.isDisplayChangeSupported()) {
System.err.println("Display mode change is not supported on this host. Test is considered passed.");
return;
}
DisplayMode defaultDisplayMode = graphicDevice.getDisplayMode();
checkDisplayMode(defaultDisplayMode);
graphicDevice.setDisplayMode(defaultDisplayMode);
DisplayMode[] displayModes = graphicDevice.getDisplayModes();
boolean isDefaultDisplayModeIncluded = false;
for (DisplayMode displayMode : displayModes) {
checkDisplayMode(displayMode);
graphicDevice.setDisplayMode(displayMode);
if (defaultDisplayMode.equals(displayMode)) {
isDefaultDisplayModeIncluded = true;
}
}
if (!isDefaultDisplayModeIncluded) {
throw new RuntimeException("Default display mode is not included");
}
}
示例5: main
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Frame frame = new Frame();
final Toolkit toolkit = Toolkit.getDefaultToolkit();
final GraphicsEnvironment graphicsEnvironment =
GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice graphicsDevice =
graphicsEnvironment.getDefaultScreenDevice();
final Dimension screenSize = toolkit.getScreenSize();
final Insets screenInsets = toolkit.getScreenInsets(
graphicsDevice.getDefaultConfiguration());
final Rectangle availableScreenBounds = new Rectangle(screenSize);
availableScreenBounds.x += screenInsets.left;
availableScreenBounds.y += screenInsets.top;
availableScreenBounds.width -= (screenInsets.left + screenInsets.right);
availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);
frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,
availableScreenBounds.width, availableScreenBounds.height);
frame.setVisible(true);
Rectangle frameBounds = frame.getBounds();
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
((SunToolkit) toolkit).realSync();
Rectangle maximizedFrameBounds = frame.getBounds();
if (maximizedFrameBounds.width < frameBounds.width
|| maximizedFrameBounds.height < frameBounds.height) {
throw new RuntimeException("Maximized frame is smaller than non maximized");
}
}
示例6: main
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
public static void main(String[] args) {
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(16, 16);
vi.validate(gc);
BufferedImage bi =
new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB);
int data[] = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData();
data[0] = 0x0000007f;
data[1] = 0x0000007f;
data[2] = 0xff00007f;
data[3] = 0xff00007f;
Graphics2D g = vi.createGraphics();
g.setComposite(AlphaComposite.SrcOver.derive(0.999f));
g.drawImage(bi, 0, 0, null);
bi = vi.getSnapshot();
if (bi.getRGB(0, 0) != bi.getRGB(1, 1)) {
throw new RuntimeException("Test FAILED: color at 0x0 ="+
Integer.toHexString(bi.getRGB(0, 0))+" differs from 1x1 ="+
Integer.toHexString(bi.getRGB(1,1)));
}
System.out.println("Test PASSED.");
}
示例7: getCompatibleImage
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
public static BufferedImage getCompatibleImage(final int width, final int height) {
if (width == 0 && height == 0) {
return null;
}
final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice device = env.getDefaultScreenDevice();
final GraphicsConfiguration config = device.getDefaultConfiguration();
return config.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
}
示例8: main
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
public static void main(final String[] args) {
final GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice gd = ge.getDefaultScreenDevice();
final GraphicsConfiguration gc = gd.getDefaultConfiguration();
final VolatileImage vi =
gc.createCompatibleVolatileImage(SIZE, SIZE, TRANSLUCENT);
final BufferedImage bi = makeUnmanagedBI(gc, TRANSLUCENT);
final int expected = bi.getRGB(2, 2);
int attempt = 0;
BufferedImage snapshot;
while (true) {
if (++attempt > 10) {
throw new RuntimeException("Too many attempts: " + attempt);
}
vi.validate(gc);
final Graphics2D g2d = vi.createGraphics();
g2d.setComposite(AlphaComposite.Src);
g2d.scale(2, 2);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2d.drawImage(bi, 0, 0, null);
g2d.dispose();
snapshot = vi.getSnapshot();
if (vi.contentsLost()) {
continue;
}
break;
}
final int actual = snapshot.getRGB(2, 2);
if (actual != expected) {
System.err.println("Actual: " + Integer.toHexString(actual));
System.err.println("Expected: " + Integer.toHexString(expected));
throw new RuntimeException("Test failed");
}
}
示例9: getGC
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
private static D3DGraphicsConfig getGC(WComponentPeer peer) {
GraphicsConfiguration gc;
if (peer != null) {
gc = peer.getGraphicsConfiguration();
} else {
GraphicsEnvironment env =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = env.getDefaultScreenDevice();
gc = gd.getDefaultConfiguration();
}
return (gc instanceof D3DGraphicsConfig) ? (D3DGraphicsConfig)gc : null;
}
示例10: getGC
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
public static CGLGraphicsConfig getGC(CPlatformView pView) {
if (pView != null) {
return (CGLGraphicsConfig)pView.getGraphicsConfiguration();
} else {
// REMIND: this should rarely (never?) happen, but what if
// default config is not CGL?
GraphicsEnvironment env = GraphicsEnvironment
.getLocalGraphicsEnvironment();
GraphicsDevice gd = env.getDefaultScreenDevice();
return (CGLGraphicsConfig) gd.getDefaultConfiguration();
}
}
示例11: getGC
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
public static GLXGraphicsConfig getGC(X11ComponentPeer peer) {
if (peer != null) {
return (GLXGraphicsConfig)peer.getGraphicsConfiguration();
} else {
// REMIND: this should rarely (never?) happen, but what if
// default config is not GLX?
GraphicsEnvironment env =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = env.getDefaultScreenDevice();
return (GLXGraphicsConfig)gd.getDefaultConfiguration();
}
}
示例12: makeVI
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
private static VolatileImage makeVI(final int type) {
final GraphicsEnvironment ge = GraphicsEnvironment
.getLocalGraphicsEnvironment();
final GraphicsDevice gd = ge.getDefaultScreenDevice();
final GraphicsConfiguration gc = gd.getDefaultConfiguration();
return gc.createCompatibleVolatileImage(SIZE, SIZE, type);
}
示例13: showDebugDialog
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
void showDebugDialog() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice defaultScreen = ge.getDefaultScreenDevice();
Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds();
pack();
setLocation((int) rect.getCenterX(), Canvas.Window.winStart.y);
setAlwaysOnTop(true);
setVisible(true);
}
示例14: getGC
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
public static WGLGraphicsConfig getGC(WComponentPeer peer) {
if (peer != null) {
return (WGLGraphicsConfig)peer.getGraphicsConfiguration();
} else {
// REMIND: this should rarely (never?) happen, but what if
// default config is not WGL?
GraphicsEnvironment env =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = env.getDefaultScreenDevice();
return (WGLGraphicsConfig)gd.getDefaultConfiguration();
}
}
示例15: getGC
import java.awt.GraphicsEnvironment; //导入方法依赖的package包/类
public static X11GraphicsConfig getGC(X11ComponentPeer peer) {
if (peer != null) {
return (X11GraphicsConfig) peer.getGraphicsConfiguration();
} else {
GraphicsEnvironment env =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = env.getDefaultScreenDevice();
return (X11GraphicsConfig)gd.getDefaultConfiguration();
}
}