Example usage for java.awt Frame getBounds

List of usage examples for java.awt Frame getBounds

Introduction

In this page you can find the example usage for java.awt Frame getBounds.

Prototype

public Rectangle getBounds() 

Source Link

Document

Gets the bounds of this component in the form of a Rectangle object.

Usage

From source file:FullScreen.java

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

    try {/*from w  ww .j  a va 2  s  .  c  om*/
        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:com.jcraft.weirdx.XWindow.java

private void addComponentListener(java.awt.Frame foo) {
    final java.awt.Frame frame = foo;
    frame.addComponentListener(new java.awt.event.ComponentAdapter() {
        public void componentResized(java.awt.event.ComponentEvent e) {
            if (parent == null)
                return;
            Rectangle rectangle = frame.getBounds();
            if (rectangle.width == 0 || rectangle.height == 0)
                return;
            if (frame_width != rectangle.width || frame_height != rectangle.height) {
                Insets insets = frame.getInsets();
                synchronized (XWindow.LOCK) {
                    try {
                        Point point = frame.getLocation();
                        int ww = rectangle.width - insets.left - insets.right - borderWidth * 2;
                        int hh = rectangle.height - insets.top - insets.bottom - borderWidth * 2;
                        if (ww > 0 && hh > 0) {
                            ddxwindow.setSize(ww, hh);
                            frame.pack();
                            Event event = new Event();
                            event.mkConfigureNotify(id, id, (rectangle.x + insets.left),
                                    (rectangle.y + insets.top), ww, hh, borderWidth,
                                    (attr & (1 << 16)) != 0 ? 1 : 0);
                            sendEvent(event, 1, null);
                            frame_x = rectangle.x;
                            frame_y = rectangle.y;
                            frame_width = rectangle.width;
                            frame_height = rectangle.height;
                        }/*  w w w . j  a  va2 s . com*/
                    } catch (Exception ee) {
                        LOG.error(ee);
                    }
                }
            }
        }
    });
}