Example usage for java.awt GraphicsEnvironment getDefaultScreenDevice

List of usage examples for java.awt GraphicsEnvironment getDefaultScreenDevice

Introduction

In this page you can find the example usage for java.awt GraphicsEnvironment getDefaultScreenDevice.

Prototype

public abstract GraphicsDevice getDefaultScreenDevice() throws HeadlessException;

Source Link

Document

Returns the default screen GraphicsDevice .

Usage

From source file:misc.ShapedWindowDemo.java

public static void main(String[] args) {
    // Determine what the GraphicsDevice can support.
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    final boolean isTranslucencySupported = gd.isWindowTranslucencySupported(TRANSLUCENT);

    //If shaped windows aren't supported, exit.
    if (!gd.isWindowTranslucencySupported(PERPIXEL_TRANSPARENT)) {
        System.err.println("Shaped windows are not supported");
        System.exit(0);/*from w w  w.jav  a2  s .  c  o m*/
    }

    //If translucent windows aren't supported, 
    //create an opaque window.
    if (!isTranslucencySupported) {
        System.out.println("Translucency is not supported, creating an opaque window");
    }

    // Create the GUI on the event-dispatching thread
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            ShapedWindowDemo sw = new ShapedWindowDemo();

            // Set the window to 70% translucency, if supported.
            if (isTranslucencySupported) {
                sw.setOpacity(0.7f);
            }

            // Display the window.
            sw.setVisible(true);
        }
    });
}

From source file:FullScreen.java

public static void main(String args[]) {
    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice graphicsDevice = graphicsEnvironment.getDefaultScreenDevice();
    DisplayMode originalDisplayMode = graphicsDevice.getDisplayMode();

    try {/*  w  w  w.  j  a v a 2 s .c o m*/
        Frame frame = new Frame();
        frame.setUndecorated(true);
        frame.setIgnoreRepaint(true);
        graphicsDevice.setFullScreenWindow(frame);
        if (graphicsDevice.isDisplayChangeSupported()) {
            graphicsDevice.setDisplayMode(getBestDisplayMode(graphicsDevice));
        }
        frame.createBufferStrategy(2); // 2 buffers
        Rectangle bounds = frame.getBounds();
        BufferStrategy bufferStrategy = frame.getBufferStrategy();
        while (!done()) {
            Graphics g = null;
            try {
                g = bufferStrategy.getDrawGraphics();
                if ((counter <= 2)) { // 2 buffers
                    g.setColor(Color.CYAN);
                    g.fillRect(0, 0, bounds.width, bounds.height);
                }
                g.setColor(Color.RED);
                // redraw prior line, too, since 2 buffers
                if (counter != 1) {
                    g.drawLine(counter - 1, (counter - 1) * 5, bounds.width, bounds.height);
                }
                g.drawLine(counter, counter * 5, bounds.width, bounds.height);
                bufferStrategy.show();
            } finally {
                if (g != null) {
                    g.dispose();
                }
            }
            try {
                Thread.sleep(250);
            } catch (InterruptedException ignored) {
            }
        }
    } finally {
        graphicsDevice.setDisplayMode(originalDisplayMode);
        graphicsDevice.setFullScreenWindow(null);
    }
    System.exit(0);
}

From source file:MultiBufferTest.java

public static void main(String[] args) {
    try {/* w ww  .  j  a v  a 2  s.  c  o  m*/
        int numBuffers = 2;
        if (args != null && args.length > 0) {
            numBuffers = Integer.parseInt(args[0]);
            if (numBuffers < 2 || numBuffers > COLORS.length) {
                System.err.println("Must specify between 2 and " + COLORS.length + " buffers");
                System.exit(1);
            }
        }
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice device = env.getDefaultScreenDevice();
        MultiBufferTest test = new MultiBufferTest(numBuffers, device);
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.exit(0);
}

From source file:Main.java

public static void main(String[] args) {
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Rectangle bounds = env.getMaximumWindowBounds();
    System.out.println("Screen Bounds: " + bounds);

    GraphicsDevice screen = env.getDefaultScreenDevice();
    GraphicsConfiguration config = screen.getDefaultConfiguration();
    System.out.println("Screen Size  : " + config.getBounds());

    JFrame frame = new JFrame("Frame Info");
    System.out.println("Frame Insets : " + frame.getInsets());

    frame.setSize(200, 200);/*from   w w  w .  j a  v  a 2  s.  c  om*/
    System.out.println("Frame Insets : " + frame.getInsets());
    frame.setVisible(true);

    System.out.println("Frame Size   : " + frame.getSize());
    System.out.println("Frame Insets : " + frame.getInsets());
    System.out.println("Content Size : " + frame.getContentPane().getSize());
}

From source file:RobotTest.java

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            // make frame with a button panel

            ButtonFrame frame = new ButtonFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);/*from   www  .  ja v a  2s  .  c  om*/

            // attach a robot to the screen device

            GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice screen = environment.getDefaultScreenDevice();

            try {
                Robot robot = new Robot(screen);
                runTest(robot);
            } catch (AWTException e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:Main.java

public static boolean isTranslucentSupported() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();

    boolean isUniformTranslucencySupported = gd
            .isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency.TRANSLUCENT);
    return isUniformTranslucencySupported;
}

From source file:Main.java

/**
 * Gets the screen resolution in an integer array.
 * /*from   www  . j  a v  a2s .  c  o  m*/
 * @return an int array containing two entries, the width and the height in
 *         pixels.
 */
public static int[] getScreenResolution() {
    final int[] result = new int[2];
    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice gd = ge.getDefaultScreenDevice();
    result[0] = gd.getDisplayMode().getWidth();
    result[1] = gd.getDisplayMode().getHeight();
    return result;
}

From source file:Main.java

public static Image getImage(Component c) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();

    // Create an image that supports transparent pixels
    BufferedImage bImage = gc.createCompatibleImage(c.getWidth(), c.getHeight(), Transparency.BITMASK);

    /*/*from w  w w .  ja  v a  2  s. c  om*/
     * And now this is how we get an image of the component
     */
    Graphics2D g = bImage.createGraphics();

    // Then use the current component we're in and call paint on this
    // graphics object
    c.paint(g);
    return bImage;
}

From source file:Main.java

public static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }//from w ww. j  ava  2 s.c  o m

    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();
    // Create a buffered image with a format that's compatible with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        GraphicsDevice gs = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gs.getDefaultConfiguration();
        VolatileImage vbimage = gc.createCompatibleVolatileImage(200, 200, gc.getImageCapabilities());
    } catch (Exception e) {
        // The system does not have a screen
    }
    return bimage;
}

From source file:Main.java

public static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }/*from   w ww  .j av  a  2  s.  co m*/

    // This code ensures that all the pixels in the image are loaded
    image = new ImageIcon(image).getImage();
    // Create a buffered image with a format that's compatible with the screen
    BufferedImage bimage = null;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    try {
        GraphicsDevice gs = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gs.getDefaultConfiguration();
        VolatileImage vbimage = gc.createCompatibleVolatileImage(200, 200);
    } catch (HeadlessException e) {
        // The system does not have a screen
    }
    return bimage;
}