canvas.createBufferStrategy(2); do { strategy = canvas.getBufferStrategy(); } while (strategy == null); start();
synchronized protected void render() { if (canvas.isDisplayable() && graphics.image != null) { if (canvas.getBufferStrategy() == null) { canvas.createBufferStrategy(2); } BufferStrategy strategy = canvas.getBufferStrategy(); if (strategy != null) { // Render single frame // try { do { // The following loop ensures that the contents of the drawing buffer // are consistent in case the underlying surface was recreated do { Graphics2D draw = (Graphics2D) strategy.getDrawGraphics(); // draw to width/height, since this may be a 2x image draw.drawImage(graphics.image, 0, 0, sketchWidth, sketchHeight, null); draw.dispose(); } while (strategy.contentsRestored()); // Display the buffer strategy.show(); // Repeat the rendering if the drawing buffer was lost } while (strategy.contentsLost()); } } }
BufferStrategy bs = getBufferStrategy(); if (bs == null) { createBufferStrategy(3);
BufferStrategy bs = this.getBufferStrategy(); if(bs == null){ this.createBufferStrategy(3);
bufferStrategy = canvas.getBufferStrategy();
BufferStrategy bs = getBufferStrategy(); if (bs == null) { createBufferStrategy(3);
BufferStrategy bs = this.getBufferStrategy(); if (bs == null) { this.createBufferStrategy(3);
bufferStrategy = gameField.getBufferStrategy();
BufferStrategy bs = this.getBufferStrategy(); if (bs == null) { createBufferStrategy(3);
BufferStrategy bs = c.getBufferStrategy(); Graphics g = bs.getDrawGraphics(); g.drawImage(img, 100, 100, null);
BufferStrategy bs = getBufferStrategy(); if (bs == null) { createBufferStrategy(3);
BufferStrategy bs = getBufferStrategy();
BufferStrategy bufferStrategy = getBufferStrategy(); if (bufferStrategy == null) { this.createBufferStrategy(3);
BufferStrategy bs = getBufferStrategy(); if (bs == null) { createBufferStrategy(3);
/** * Prepare windowed mode. * * @param output The output resolution * @throws LionEngineException If unable to initialize windowed mode. */ private void initWindowed(Resolution output) { final Canvas canvas = new Canvas(conf); canvas.setBackground(Color.BLACK); canvas.setEnabled(true); canvas.setVisible(true); canvas.setIgnoreRepaint(true); frame.add(canvas); canvas.setPreferredSize(new Dimension(output.getWidth(), output.getHeight())); frame.pack(); frame.setLocationRelativeTo(null); ToolsAwt.createBufferStrategy(canvas, conf); buf = canvas.getBufferStrategy(); // Set input listeners componentForKeyboard = canvas; componentForMouse = canvas; componentForCursor = frame; frame.validate(); }
add(drawArea); createBufferStrategy(2); bufferStrategy = drawArea.getBufferStrategy();
strategy = getBufferStrategy(); Graphics g = strategy.getDrawGraphics(); this.g2 = (Graphics2D) g;
BufferStrategy bs = this.getBufferStrategy();
@Override public void paint(Graphics g) { // Calling BufferStrategy.show() here sometimes throws // NullPointerException or IllegalStateException, // but otherwise seems to work fine. try { if (canvas.getWidth() <= 0 || canvas.getHeight() <= 0) { return; } BufferStrategy strategy = canvas.getBufferStrategy(); do { do { g = strategy.getDrawGraphics(); if (color != null) { g.setColor(color); g.fillRect(0, 0, getWidth(), getHeight()); } if (image != null) { g.drawImage(image, 0, 0, getWidth(), getHeight(), null); } if (buffer != null) { g.drawImage(buffer, 0, 0, getWidth(), getHeight(), null); } g.dispose(); } while (strategy.contentsRestored()); strategy.show(); } while (strategy.contentsLost()); } catch (NullPointerException e) { } catch (IllegalStateException e) { } } };
BufferStrategy bs = getBufferStrategy(); if (bs== null){ createBufferStrategy(3);