当前位置: 首页>>代码示例>>Java>>正文


Java BufferStrategy.contentsRestored方法代码示例

本文整理汇总了Java中java.awt.image.BufferStrategy.contentsRestored方法的典型用法代码示例。如果您正苦于以下问题:Java BufferStrategy.contentsRestored方法的具体用法?Java BufferStrategy.contentsRestored怎么用?Java BufferStrategy.contentsRestored使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.image.BufferStrategy的用法示例。


在下文中一共展示了BufferStrategy.contentsRestored方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: render

import java.awt.image.BufferStrategy; //导入方法依赖的package包/类
/**
 * Render offscreen graphics into the frame.
 */
private void render() {
    final BufferStrategy bufferStrategy = frame.getBufferStrategy();
    do {
        do {
            final Graphics2D graphics = (Graphics2D) bufferStrategy.getDrawGraphics();
            // canvas is not opaque, so fill with background color
            graphics.setPaint(background);
            graphics.fillRect(0, 0, 400, 400);
            // then let canvas render into graphics
            canvas.render(graphics);
            graphics.dispose();
        } while (bufferStrategy.contentsRestored());
        bufferStrategy.show();
    } while (bufferStrategy.contentsLost());
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:OffscreenCanvasExample.java

示例2: render

import java.awt.image.BufferStrategy; //导入方法依赖的package包/类
public void render() {
    ImageCapabilities imgBackBufCap = new ImageCapabilities(true);
    ImageCapabilities imgFrontBufCap = new ImageCapabilities(true);
    BufferCapabilities bufCap =
        new BufferCapabilities(imgFrontBufCap,
            imgBackBufCap, BufferCapabilities.FlipContents.COPIED);
    try {

        createBufferStrategy(2, bufCap);
    } catch (AWTException ex) {
        createBufferStrategy(2);
    }

    BufferStrategy bs = getBufferStrategy();
    do {
        Graphics g =  bs.getDrawGraphics();
        g.setColor(Color.green);
        g.fillRect(0, 0, getWidth(), getHeight());

        g.setColor(Color.red);
        g.drawString("Rendering test", 20, 20);

        g.drawImage(bi, 50, 50, null);

        g.dispose();
        bs.show();
    } while (bs.contentsLost()||bs.contentsRestored());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:BufferStrategyExceptionTest.java

示例3: draw

import java.awt.image.BufferStrategy; //导入方法依赖的package包/类
/** Draws every character of every row onto the canvas. */
public void draw() {
    final BufferStrategy bs = this.getBufferStrategy();

    do {
        do {
            final Graphics2D gc;

            try {
                gc = (Graphics2D) bs.getDrawGraphics();
            } catch (final NullPointerException | IllegalStateException e) {
                // BufferStrategy may not have been created on the first call,
                // so just do a recursive call until it works.
                // This may be a bad idea.
                draw();
                return;
            }

            gc.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
            gc.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
            gc.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
            gc.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);

            // Font characters are pre-rendered images, so no need for AA.
            gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

            // No-need for text rendering related options.
            gc.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
            gc.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);

            // If alpha is used in the character images, we want computations related to drawing them to be fast.
            gc.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);

            screen.draw(gc, imageCache);
            gc.dispose();
        } while (bs.contentsRestored()); // Repeat render if drawing buffer contents were restored.

        bs.show();
    } while (bs.contentsLost()); // Repeat render if drawing buffer was lost.
}
 
开发者ID:Valkryst,项目名称:VTerminal,代码行数:41,代码来源:Panel.java

示例4: drawScene

import java.awt.image.BufferStrategy; //导入方法依赖的package包/类
@Override
public void drawScene(Snowflake[] scene, ScreenParameters screenParameters) {
    if (DEBUG_SHOW_FPS) fpsCounter.recordFrame();

    BufferStrategy strategy = getBufferStrategy();
    do {
        do {
            Graphics2D g2d = (Graphics2D) strategy.getDrawGraphics();
            SnowFlake3DRenderer snowFlake3DRenderer = new AwtSnowflakeRenderer(g2d, screenParameters);

            drawBackground(g2d, screenParameters);
            for (Snowflake snowflake : scene) {
                snowFlake3DRenderer.renderSnowflake(snowflake.x + xoffset, snowflake.y, snowflake.size, snowflake.z, screenParameters);
            }

            if (DEBUG_SHOW_FPS) {
                g2d.setColor(Color.white);
                g2d.drawString(String.format("%.2f min FPS", fpsCounter.getMinFps()), 20, 20);
                g2d.drawString(String.format("%.2f max FPS", fpsCounter.getMaxFps()), 20, 35);
            }

            g2d.dispose();

        } while (strategy.contentsRestored());

        strategy.show();
        DEFAULT_TOOLKIT.sync(); // Seems like this is necessary on Ubuntu for smooth animation
    } while (strategy.contentsLost());
}
 
开发者ID:martinmarinov,项目名称:snowstorm,代码行数:30,代码来源:AwtCanvasPainter.java

示例5: doUpdate

import java.awt.image.BufferStrategy; //导入方法依赖的package包/类
private void doUpdate() {
	BufferStrategy bufferStrategy = jFrame.getBufferStrategy();
	
	do {
		do {
			Graphics graphics = bufferStrategy.getDrawGraphics();
			graphics.dispose();
		} while(bufferStrategy.contentsRestored());
		
		bufferStrategy.show();
	} while(bufferStrategy.contentsLost());
}
 
开发者ID:WavePropagation,项目名称:org.dayflower,代码行数:13,代码来源:ProgressUpdateFutureImpl.java

示例6: doProcess

import java.awt.image.BufferStrategy; //导入方法依赖的package包/类
private void doProcess() {
	long elapsedTime = System.currentTimeMillis() - currentTime;
	
	currentTime += elapsedTime;
	
	BufferStrategy bufferStrategy = jFrame.getBufferStrategy();
	
	int width = jFrame.getWidth();
	int height = jFrame.getHeight();
	
	do {
		do {
			Graphics graphics = null;
			
			try {
				graphics = bufferStrategy.getDrawGraphics();
			} catch(IllegalStateException | NullPointerException e) {
				
			}
			
			if(graphics == null) {
				return;
			}
			
			Graphics2D graphics2D = Graphics2D.class.cast(graphics);
			
			if(Constants.isRenderingInRealtime()) {
				graphics2D.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
				graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
				graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
			} else {
				graphics2D.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
				graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
				graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
			}
			
			graphics2D.clearRect(0, 0, width, height);
			graphics2D.drawImage(bufferedImage, 0, 0, width, height, null);
			graphics2D.setColor(Color.WHITE);
			graphics2D.drawString("FPS " + newFPS, 20, 70);
			graphics2D.dispose();
		} while(bufferStrategy.contentsRestored());
			bufferStrategy.show();
	} while(bufferStrategy.contentsLost());
	
	Toolkit.getDefaultToolkit().sync();
	
	this.elapsedTime += elapsedTime;
	
	oldFPS++;
	
	if(this.elapsedTime >= 1000L) {
		this.elapsedTime -= 1000L;
		
		newFPS = oldFPS;
		oldFPS = 0;
	}
}
 
开发者ID:WavePropagation,项目名称:org.dayflower,代码行数:59,代码来源:JFrameDisplay.java


注:本文中的java.awt.image.BufferStrategy.contentsRestored方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。