本文整理匯總了Java中java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment方法的典型用法代碼示例。如果您正苦於以下問題:Java GraphicsEnvironment.getLocalGraphicsEnvironment方法的具體用法?Java GraphicsEnvironment.getLocalGraphicsEnvironment怎麽用?Java GraphicsEnvironment.getLocalGraphicsEnvironment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.GraphicsEnvironment
的用法示例。
在下文中一共展示了GraphicsEnvironment.getLocalGraphicsEnvironment方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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");
}
}
示例2: 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();
}
示例3: loadResources
import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
public static void loadResources() {
try(InputStream mainFontIn = FontResources.class.getClassLoader().getResourceAsStream("hyperbox/mafia/resources/fonts/ubuntu.ttf");
InputStream mainFontBoldIn = FontResources.class.getClassLoader().getResourceAsStream("hyperbox/mafia/resources/fonts/ubuntuBold.ttf")) {
mainFont = Font.createFont(Font.TRUETYPE_FONT, mainFontIn);
mainFontBold = Font.createFont(Font.TRUETYPE_FONT, mainFontBoldIn);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(mainFont);
ge.registerFont(mainFontBold);
} catch (IOException | FontFormatException e) {
e.printStackTrace();
System.exit(-1);
}
}
示例4: main
import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
GraphicsEnvironment.getLocalGraphicsEnvironment();
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
String mime = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();
StreamPrintServiceFactory[] factories =
StreamPrintServiceFactory.
lookupStreamPrintServiceFactories(flavor, mime);
if (factories.length == 0) {
System.out.println("No print service found.");
return;
}
FileOutputStream output = new FileOutputStream("out.ps");
StreamPrintService service = factories[0].getPrintService(output);
SimpleDoc doc =
new SimpleDoc(new PrintSEUmlauts(),
DocFlavor.SERVICE_FORMATTED.PRINTABLE,
new HashDocAttributeSet());
DocPrintJob job = service.createPrintJob();
job.addPrintJobListener(new PrintJobAdapter() {
@Override
public void printJobCompleted(PrintJobEvent pje) {
testPrintAndExit();
}
});
job.print(doc, new HashPrintRequestAttributeSet());
}
示例5: getScreenBounds
import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
private Rectangle getScreenBounds() throws HeadlessException {
Rectangle virtualBounds = new Rectangle();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
if (gs.length == 0 || gs.length == 1) {
return new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
}
for (GraphicsDevice gd : gs) {
virtualBounds = virtualBounds.union(gd.getDefaultConfiguration().getBounds());
}
return virtualBounds;
}
示例6: main
import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
public static void main(String[] args) throws AWTException
{
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
if (gds.length < 2) {
System.out.println("It's a multiscreen test... skipping!");
return;
}
for (int i = 0; i < gds.length; ++i) {
GraphicsDevice gd = gds[i];
GraphicsConfiguration gc = gd.getDefaultConfiguration();
Rectangle screen = gc.getBounds();
Robot robot = new Robot(gd);
// check Robot.mouseMove()
robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y);
Point mouse = MouseInfo.getPointerInfo().getLocation();
Point point = screen.getLocation();
point.translate(mouseOffset.x, mouseOffset.y);
if (!point.equals(mouse)) {
throw new RuntimeException(getErrorText("Robot.mouseMove", i));
}
// check Robot.getPixelColor()
Frame frame = new Frame(gc);
frame.setUndecorated(true);
frame.setSize(100, 100);
frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y);
frame.setBackground(color);
frame.setVisible(true);
robot.waitForIdle();
Rectangle bounds = frame.getBounds();
if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) {
throw new RuntimeException(getErrorText("Robot.getPixelColor", i));
}
// check Robot.createScreenCapture()
BufferedImage image = robot.createScreenCapture(bounds);
int rgb = color.getRGB();
if (image.getRGB(0, 0) != rgb
|| image.getRGB(image.getWidth() - 1, 0) != rgb
|| image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb
|| image.getRGB(0, image.getHeight() - 1) != rgb) {
throw new RuntimeException(
getErrorText("Robot.createScreenCapture", i));
}
frame.dispose();
}
System.out.println("Test PASSED!");
}
示例7: isOutOfScreen
import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
/**
* @return False if the given point is not inside any screen device that are currently available.
*/
private static boolean isOutOfScreen( int x, int y ) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
for( int j=0; j<gs.length; j++ ) {
GraphicsDevice gd = gs[j];
if( gd.getType() != GraphicsDevice.TYPE_RASTER_SCREEN )
continue;
Rectangle bounds = gd.getDefaultConfiguration().getBounds();
if( bounds.contains( x, y ) )
return false;
}
return true;
}
示例8: main
import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
public static void main(String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment
.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice()
.getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(100, 100);
Graphics2D g2d = vi.createGraphics();
g2d.scale(2, 2);
BufferedImage img = new BufferedImage(50, 50,
BufferedImage.TYPE_INT_ARGB);
g2d.drawImage(img, 10, 25, Color.blue, null);
g2d.dispose();
}
示例9: VolatileSurfaceManager
import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
protected VolatileSurfaceManager(SunVolatileImage vImg, Object context) {
this.vImg = vImg;
this.context = context;
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
// We could have a HeadlessGE at this point, so double-check before
// assuming anything.
if (ge instanceof SunGraphicsEnvironment) {
((SunGraphicsEnvironment)ge).addDisplayChangedListener(this);
}
}
示例10: 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);
}
示例11: setScreenAndDimensions
import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
private void setScreenAndDimensions(JFrame frame) {
// check multiple displays
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
String display = Config.instance().to().getString(Config.Entry.SCREEN.key(), "-");
GraphicsDevice[] screens = ge.getScreenDevices();
if (screens.length == 1) {
setDimensions(frame,
Config.instance().to().getInt(Config.Entry.POS_X.key(), -1),
Config.instance().to().getInt(Config.Entry.POS_Y.key(), -1),
Config.instance().to().getInt(Config.Entry.POS_WIDTH.key(), -1),
Config.instance().to().getInt(Config.Entry.POS_HEIGHT.key(), -1));
} else {
for (GraphicsDevice screen : screens) { // if multiple screens available then try to open on saved display
if (screen.getIDstring().contentEquals(display)) {
JFrame dummy = new JFrame(screen.getDefaultConfiguration());
frame.setLocationRelativeTo(dummy);
dummy.dispose();
Rectangle screenBounds = screen.getDefaultConfiguration().getBounds();
Point pos = new Point(Config.instance().to().getInt(Config.Entry.SCREEN_POS_X.key(), -1),
Config.instance().to().getInt(Config.Entry.SCREEN_POS_Y.key(), -1));
if (pos.x >= 0 && pos.y >= 0) {
pos.x += screenBounds.x;
pos.y += screenBounds.y;
logger.info(" new pos {} {} ", pos.x, pos.y);
}
setDimensions(frame,
pos.x,
pos.y,
Config.instance().to().getInt(Config.Entry.SCREEN_POS_WIDTH.key(), -1),
Config.instance().to().getInt(Config.Entry.SCREEN_POS_HEIGHT.key(), -1));
break;
}
}
}
}
示例12: main
import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
robot = new Robot();
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
UIManager.LookAndFeelInfo[] lookAndFeelArray =
UIManager.getInstalledLookAndFeels();
for (GraphicsDevice sd : ge.getScreenDevices()) {
for (UIManager.LookAndFeelInfo lookAndFeelItem : lookAndFeelArray) {
executeCase(lookAndFeelItem.getClassName(), sd);
robot.waitForIdle();
}
}
}
示例13: 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.");
}
示例14: activateDisplayListener
import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
/**
* This method should be called from subclasses which create
* cached SurfaceData objects that depend on the current
* properties of the display.
*/
protected void activateDisplayListener() {
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
// We could have a HeadlessGE at this point, so double-check before
// assuming anything.
// Also, no point in listening to display change events if
// the image is never going to be accelerated.
if (ge instanceof SunGraphicsEnvironment) {
((SunGraphicsEnvironment)ge).addDisplayChangedListener(this);
}
}
示例15: run
import java.awt.GraphicsEnvironment; //導入方法依賴的package包/類
public void run()
{
GraphicsEnvironment ge = null;
// -= Simon Lessard =-
// TODO: Check if synchronization is required
Hashtable<String, Boolean> fontNames = null;
try
{
ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
if (ge != null)
{
String[] families = ge.getAvailableFontFamilyNames();
if ((families != null) && (families.length > 0))
{
fontNames = new Hashtable<String, Boolean>(families.length);
for (int i = 0; i < families.length; i++)
{
String name = families[i].toLowerCase();
fontNames.put(name, Boolean.TRUE);
}
}
}
}
catch (Throwable t)
{
// If any exception occurs during getLocalGraphicsEnvironment(),
// we assume we've got a non-graphical environment
_LOG.warning(_EXCEPTION_MESSAGE, t);
}
__setFontsLoaded(fontNames);
}