本文整理匯總了Java中java.awt.GraphicsEnvironment類的典型用法代碼示例。如果您正苦於以下問題:Java GraphicsEnvironment類的具體用法?Java GraphicsEnvironment怎麽用?Java GraphicsEnvironment使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
GraphicsEnvironment類屬於java.awt包,在下文中一共展示了GraphicsEnvironment類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import java.awt.GraphicsEnvironment; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
DisplayChangeVITest test = new DisplayChangeVITest();
GraphicsDevice gd =
GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice();
if (gd.isFullScreenSupported()) {
gd.setFullScreenWindow(test);
Thread t = new Thread(test);
t.run();
synchronized (lock) {
while (!done) {
try {
lock.wait(50);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
System.err.println("Test Passed.");
} else {
System.err.println("Full screen not supported. Test passed.");
}
}
示例2: isAccelerated
import java.awt.GraphicsEnvironment; //導入依賴的package包/類
public boolean isAccelerated() {
// Note that when img.getAccelerationPriority() gets set to 0
// we remove SurfaceDataProxy objects from the cache and the
// answer will be false.
GraphicsConfiguration tmpGc = gc;
if (tmpGc == null) {
tmpGc = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration();
}
if (tmpGc instanceof ProxiedGraphicsConfig) {
Object proxyKey =
((ProxiedGraphicsConfig) tmpGc).getProxyKey();
if (proxyKey != null) {
SurfaceDataProxy sdp =
(SurfaceDataProxy) getCacheData(proxyKey);
return (sdp != null && sdp.isAccelerated());
}
}
return false;
}
示例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) {
int depth = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration().
getColorModel().getPixelSize();
if (depth < 16) {
System.out.println("Test PASSED (depth < 16bit)");
return;
}
latch = new CountDownLatch(1);
RenderingToCachedGraphicsTest t1 = new RenderingToCachedGraphicsTest();
t1.pack();
t1.setSize(300, 300);
t1.setVisible(true);
try { latch.await(); } catch (InterruptedException ex) {}
t1.dispose();
if (failed) {
throw new
RuntimeException("Failed: rendering didn't show up");
}
System.out.println("Test PASSED");
}
示例5: createImageOfTab
import java.awt.GraphicsEnvironment; //導入依賴的package包/類
@Override
public Image createImageOfTab(int index) {
TabData td = displayer.getModel().getTab(index);
JLabel lbl = new JLabel(td.getText());
int width = lbl.getFontMetrics(lbl.getFont()).stringWidth(td.getText());
int height = lbl.getFontMetrics(lbl.getFont()).getHeight();
width = width + td.getIcon().getIconWidth() + 6;
height = Math.max(height, td.getIcon().getIconHeight()) + 5;
GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration();
BufferedImage image = config.createCompatibleImage(width, height);
Graphics2D g = image.createGraphics();
g.setColor(lbl.getForeground());
g.setFont(lbl.getFont());
td.getIcon().paintIcon(lbl, g, 0, 0);
g.drawString(td.getText(), 18, height / 2);
return image;
}
示例6: 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");
}
}
示例7: setVisible
import java.awt.GraphicsEnvironment; //導入依賴的package包/類
public void setVisible(boolean visible) {
if (owner == null) {
final GraphicsDevice screen = GraphicsEnvironment.
getLocalGraphicsEnvironment().
getScreenDevices()[0];
final GraphicsConfiguration config = screen.getDefaultConfiguration();
final int screenWidth = config.getBounds().width;
final int screenHeight = config.getBounds().height;
setLocation(
(screenWidth - getSize().width) / 2,
(screenHeight - getSize().height) / 2);
} else {
setLocation(
owner.getLocation().x + DIALOG_FRAME_WIDTH_DELTA,
owner.getLocation().y + DIALOG_FRAME_WIDTH_DELTA);
}
super.setVisible(visible);
}
示例8: getScreenBoundsForPoint
import java.awt.GraphicsEnvironment; //導入依賴的package包/類
/**
* Returns the screen coordinates for the monitor that contains the
* specified point. This is useful for setups with multiple monitors,
* to ensure that popup windows are positioned properly.
*
* @param x The x-coordinate, in screen coordinates.
* @param y The y-coordinate, in screen coordinates.
* @return The bounds of the monitor that contains the specified point.
*/
public static Rectangle getScreenBoundsForPoint(int x, int y) {
GraphicsEnvironment env = GraphicsEnvironment.
getLocalGraphicsEnvironment();
GraphicsDevice[] devices = env.getScreenDevices();
for (int i=0; i<devices.length; i++) {
GraphicsConfiguration[] configs = devices[i].getConfigurations();
for (int j=0; j<configs.length; j++) {
Rectangle gcBounds = configs[j].getBounds();
if (gcBounds.contains(x, y)) {
return gcBounds;
}
}
}
// If point is outside all monitors, default to default monitor (?)
return env.getMaximumWindowBounds();
}
示例9: main
import java.awt.GraphicsEnvironment; //導入依賴的package包/類
public static void main(String[] args) {
boolean iaeThrown = false;
GraphicsEnvironment ge = GraphicsEnvironment.
getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice().
getDefaultConfiguration();
try {
VolatileImage volatileImage = gc.createCompatibleVolatileImage(0, 0);
} catch (IllegalArgumentException iae) {
iaeThrown = true;
}
if (!iaeThrown) {
throw new RuntimeException ("IllegalArgumentException not thrown " +
"for createCompatibleVolatileImage(0,0)");
}
}
示例10: initFonts
import java.awt.GraphicsEnvironment; //導入依賴的package包/類
/**
* Initializes the fonts for this application.
*/
private static void initFonts() {
final String extension = ".ttf";
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
try {
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT,
new File(FONT_FILE_PATH + CAVIAR_FONT_NAME.replace(" ", "") + extension)));
} catch (FontFormatException | IOException e) {
logger.logError("An error occured while trying to register the font: " + CAVIAR_FONT_NAME + extension);
}
NAME_FONT = new Font(CAVIAR_FONT_NAME, Font.BOLD, 18);
SMALL_NAME_FONT = new Font(CAVIAR_FONT_NAME, Font.PLAIN, 15);
STATS_FONT = new Font(CAVIAR_FONT_NAME, Font.PLAIN, 18);
}
示例11: activate
import java.awt.GraphicsEnvironment; //導入依賴的package包/類
/** Activates or deactivates Drag support on asociated JTree
* component
* @param active true if the support should be active, false
* otherwise
*/
public void activate(boolean active) {
if (this.active == active) {
return;
}
this.active = active;
if (GraphicsEnvironment.isHeadless()) {
return;
}
getDropTarget().setActive(active);
//we want to support drop into scroll pane's free area and treat it as 'root node drop'
if( null == outerDropTarget ) {
outerDropTarget = new DropTarget(view.getViewport(), view.getAllowedDropActions(), this, false);
}
outerDropTarget.setActive(active);
}
示例12: main
import java.awt.GraphicsEnvironment; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
GraphicsDevice[] sds = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getScreenDevices();
for (final GraphicsDevice gd : sds) {
fail = true;
Robot robot = new Robot(gd);
robot.setAutoDelay(100);
robot.setAutoWaitForIdle(true);
Frame frame = new Frame(gd.getDefaultConfiguration());
frame.setUndecorated(true);
frame.setSize(400, 400);
frame.setVisible(true);
robot.waitForIdle();
frame.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
System.out.println("e = " + e);
fail = false;
}
});
Rectangle bounds = frame.getBounds();
robot.mouseMove(bounds.x + bounds.width / 2,
bounds.y + bounds.height / 2);
robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
frame.dispose();
if (fail) {
System.err.println("Frame bounds = " + bounds);
throw new RuntimeException("Click in the wrong location");
}
}
}
示例13: testHeadful
import java.awt.GraphicsEnvironment; //導入依賴的package包/類
private static void testHeadful() {
GraphicsEnvironment ge
= GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsConfiguration gc
= ge.getDefaultScreenDevice().getDefaultConfiguration();
Dimension gcSize = gc.getBounds().getSize();
ColorModel gcCM = gc.getColorModel();
Dimension toolkitSize = Toolkit.getDefaultToolkit().getScreenSize();
ColorModel toolkitCM = Toolkit.getDefaultToolkit().getColorModel();
if (!gcSize.equals(toolkitSize)) {
System.err.println("Toolkit size = " + toolkitSize);
System.err.println("GraphicsConfiguration size = " + gcSize);
throw new RuntimeException("Incorrect size");
}
if (!gcCM.equals(toolkitCM)) {
System.err.println("Toolkit color model = " + toolkitCM);
System.err.println("GraphicsConfiguration color model = " + gcCM);
throw new RuntimeException("Incorrect color model");
}
}
示例14: getRootWindow
import java.awt.GraphicsEnvironment; //導入依賴的package包/類
/**
* Xinerama-aware version of XlibWrapper.RootWindow method.
*/
public static long getRootWindow(int screenNumber)
{
XToolkit.awtLock();
try
{
X11GraphicsEnvironment x11ge = (X11GraphicsEnvironment)
GraphicsEnvironment.getLocalGraphicsEnvironment();
if (x11ge.runningXinerama())
{
// all the Xinerama windows share the same root window
return XlibWrapper.RootWindow(XToolkit.getDisplay(), 0);
}
else
{
return XlibWrapper.RootWindow(XToolkit.getDisplay(), screenNumber);
}
}
finally
{
XToolkit.awtUnlock();
}
}
示例15: getDesktop
import java.awt.GraphicsEnvironment; //導入依賴的package包/類
/**
* Returns the <code>Desktop</code> instance of the current
* browser context. On some platforms the Desktop API may not be
* supported; use the {@link #isDesktopSupported} method to
* determine if the current desktop is supported.
* @return the Desktop instance of the current browser context
* @throws HeadlessException if {@link
* GraphicsEnvironment#isHeadless()} returns {@code true}
* @throws UnsupportedOperationException if this class is not
* supported on the current platform
* @see #isDesktopSupported()
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public static synchronized Desktop getDesktop(){
if (GraphicsEnvironment.isHeadless()) throw new HeadlessException();
if (!Desktop.isDesktopSupported()) {
throw new UnsupportedOperationException("Desktop API is not " +
"supported on the current platform");
}
sun.awt.AppContext context = sun.awt.AppContext.getAppContext();
Desktop desktop = (Desktop)context.get(Desktop.class);
if (desktop == null) {
desktop = new Desktop();
context.put(Desktop.class, desktop);
}
return desktop;
}