Example usage for java.awt.image BufferStrategy contentsLost

List of usage examples for java.awt.image BufferStrategy contentsLost

Introduction

In this page you can find the example usage for java.awt.image BufferStrategy contentsLost.

Prototype

public abstract boolean contentsLost();

Source Link

Document

Returns whether the drawing buffer was lost since the last call to getDrawGraphics .

Usage

From source file:MultiBufferTest.java

public MultiBufferTest(int numBuffers, GraphicsDevice device) {
    try {/*from w  w  w . j a  va  2s . c  om*/
        GraphicsConfiguration gc = device.getDefaultConfiguration();
        mainFrame = new Frame(gc);
        mainFrame.setUndecorated(true);
        mainFrame.setIgnoreRepaint(true);
        device.setFullScreenWindow(mainFrame);
        if (device.isDisplayChangeSupported()) {
            chooseBestDisplayMode(device);
        }
        Rectangle bounds = mainFrame.getBounds();
        mainFrame.createBufferStrategy(numBuffers);
        BufferStrategy bufferStrategy = mainFrame.getBufferStrategy();
        for (float lag = 2000.0f; lag > 0.00000006f; lag = lag / 1.33f) {
            for (int i = 0; i < numBuffers; i++) {
                Graphics g = bufferStrategy.getDrawGraphics();
                if (!bufferStrategy.contentsLost()) {
                    g.setColor(COLORS[i]);
                    g.fillRect(0, 0, bounds.width, bounds.height);
                    bufferStrategy.show();
                    g.dispose();
                }
                try {
                    Thread.sleep((int) lag);
                } catch (InterruptedException e) {
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        device.setFullScreenWindow(null);
    }
}

From source file:Filter3dTest.java

/**
 * Updates the display.//w  w  w  .j  a va2  s.  c  o  m
 */
public void update() {
    Window window = device.getFullScreenWindow();
    if (window != null) {
        BufferStrategy strategy = window.getBufferStrategy();
        if (!strategy.contentsLost()) {
            strategy.show();
        }
    }
    // Sync the display on some systems.
    // (on Linux, this fixes event queue problems)
    Toolkit.getDefaultToolkit().sync();
}