Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This work is licensed under a Creative Commons Attribution 3.0 Unported License, available
- * at http://creativecommons.org/licenses/by/3.0/
- *
- * Please attribute by not editing the @author lines in any location on the source code.
- * Last modified 1/6/2013
- */
- import java.awt.Canvas;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.image.BufferStrategy;
- /**
- * A basic canvas class with a double buffering strategy
- * @author /u/Tjstretchalot
- */
- public class CanvasTest extends Canvas {
- /**
- * Creates the canvas
- * @param doubleBuf double buffering enabled
- */
- public CanvasTest() {
- }
- public void setDoubleBuffered(boolean doubleBuf) {
- if(doubleBuf) {
- createBufferStrategy(2);
- }else {
- createBufferStrategy(1);
- }
- }
- /**
- * Draw a red rectangle
- * @param g the graphics
- */
- public void paint(Graphics g) {
- g.setColor(Color.RED);
- g.fillRect(100, 100, 100, 100);
- }
- public void render() {
- BufferStrategy bs= getBufferStrategy();
- Graphics g = bs.getDrawGraphics();
- paint(g);
- g.dispose();
- bs.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement