本文整理了Java中java.awt.image.BufferStrategy
类的一些代码示例,展示了BufferStrategy
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BufferStrategy
类的具体详情如下:
包路径:java.awt.image.BufferStrategy
类名称:BufferStrategy
暂无
代码示例来源:origin: stackoverflow.com
frame = new JFrame();
frame.addWindowListener(new FrameClose());
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.setSize(width * scale, height * scale);
frame.setVisible(true);
canvas.setSize(width * scale, height * scale);
frame.add(canvas, 0);
if (graphics == null) {
try {
graphics = (Graphics2D) strategy.getDrawGraphics();
} catch (IllegalStateException e) {
return null;
graphics.dispose();
graphics = null;
try {
strategy.show();
Toolkit.getDefaultToolkit().sync();
return (!strategy.contentsLost());
bg.drawImage(background, 0, 0, width * scale, height
* scale, 0, 0, width, height, null);
} else {
bg.drawImage(background, 0, 0, null);
bg.dispose();
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
Graphics2D g2d = (Graphics2D) strategy.getDrawGraphics();
if (g2d == null) {
Logger.getLogger(AwtPanel.class.getName()).log(Level.WARNING, "OGL: DrawGraphics was null.");
strategy.show();
} while (strategy.contentsRestored());
} while (strategy.contentsLost());
代码示例来源:origin: stackoverflow.com
@Override
protected void Draw() {
BufferStrategy bs = getBufferStrategy();
Graphics g = bs.getDrawGraphics(); // acquire the graphics
// draw stuff here
bs.show(); // swap buffers
}
代码示例来源:origin: stackoverflow.com
JFrame frame = new JFrame("Finland2D");
frame.setPreferredSize(new Dimension(765, 500));
final Game game = new Game();
game.playing = true;
frame.add(game);
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter(){
Graphics2D g = (Graphics2D) b.getDrawGraphics();
g.setColor(Color.BLACK);
g.fillRect(0, 0, getWidth(), getHeight());
g.dispose();
b.show();
代码示例来源:origin: stackoverflow.com
frame = new JFrame("Prototyping");
JPanel panel = (JPanel) frame.getContentPane();
panel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
panel.setLayout(new GridLayout());
canvas.setIgnoreRepaint(true);
panel.add(canvas);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setResizable(false);
frame.setVisible(true);
canvas.requestFocus();
Graphics2D g = (Graphics2D) bufferStrategy.getDrawGraphics();
g.clearRect(0, 0, WIDTH, HEIGHT);
render(g);
g.dispose();
bufferStrategy.show();
g.setColor(Color.GRAY);
g.fillRect(0, 0, WIDTH, HEIGHT);
代码示例来源:origin: stackoverflow.com
setPreferredSize(dims); // actual screen size
image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
running = false;
Graphics2D g2d = (Graphics2D) image.getGraphics().create();
g2d.fillRect((WIDTH / 2) - 25, (HEIGHT / 2) - 25, 50, 50);
g2d.dispose();
return;
g2d = (Graphics2D) bs.getDrawGraphics().create();
g2d.drawImage(image, 0, 0, getWidth(), getHeight(), null);
g2d.dispose();
bs.show();
Test test = new Test(new Dimension(800, 600));
frame.getContentPane().add(test);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setResizable(false);
代码示例来源:origin: stackoverflow.com
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(new BorderLayout());
getContentPane().setPreferredSize(new Dimension(800, 600));
gameField.setIgnoreRepaint(true);
gameField.setPreferredSize(new Dimension(800, 580));
getContentPane().add(gameField, BorderLayout.CENTER);
scroll.setPreferredSize(new Dimension(800, 20));
scroll.setMaximum(1400 - 800); // image width - viewport width
getContentPane().add(scroll, BorderLayout.SOUTH);
this.pack();
Graphics g = null;
try {
g = bufferStrategy.getDrawGraphics();
drawSprites(g);
} finally {
g.dispose();
bufferStrategy.show();
Toolkit.getDefaultToolkit().sync();
g2d2.setColor(Color.YELLOW); // clear background
g2d2.fillRect(0, 0, 1400, 580); // again, fixed width/height only for SSCCE
g2d2.setColor(Color.BLACK);
代码示例来源:origin: stackoverflow.com
Graphics g = (Graphics) bufferStrategy.getDrawGraphics();
g.clearRect(0, 0, super.getWidth(), super.getHeight());
g.drawImage(img, tickCount, 0, null);
Font font = new Font("Verdana", 0, 11);
g.setFont(font);
g.setColor(Color.RED);
g.drawString(NAME + " / " + fps + " fps, " + tps + "tps", 5, 15);
g.dispose();
bufferStrategy.show();
game.setPreferredSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
game.setMinimumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
game.setMaximumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
JFrame frame = new JFrame(Game.NAME);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(game);
frame.pack();
frame.setResizable(true);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
代码示例来源:origin: stackoverflow.com
running = true;
new Thread(this).start();
this.addMouseListener(this);
Graphics g = bs.getDrawGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
* 2);
g.setColor(Color.black);
g.fillRect((int) (x - 8) + this.getWidth() / 2,
(int) (y - 8) + this.getHeight() / 2, 16, 16);
g.dispose();
bs.show();
game.setMinimumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
game.setMaximumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
game.setPreferredSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
代码示例来源:origin: stackoverflow.com
engine.gameStart();
setFocusable(true);
requestFocusInWindow();
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
return new Dimension(200, 200);
int x = col * 128;
int y = row * 128;
g2d.drawImage(getTile(tile), x, y, null);
g2d.dispose();
do {
Graphics2D g2d = (Graphics2D) bs.getDrawGraphics();
if (g2d != null) {
g2d.drawImage(map, camX, camY, null);
} while (bs.contentsLost());
bs.show();
代码示例来源:origin: stackoverflow.com
JFrame frame = new JFrame("Image Test");
frame.setSize(400, 800);
frame.setVisible(true);
frame.setFocusable(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
canvas.setPreferredSize(new Dimension(400, 800));
canvas.setMaximumSize(new Dimension(400, 800));
canvas.setMinimumSize(new Dimension(400, 800));
frame.add(canvas);
BufferStrategy bs = canvas.getBufferStrategy();
Graphics g = bs.getDrawGraphics();
g.clearRect(0, 0, 400, 800);
g.drawImage(image, 0, 0, null);
bs.show();
g.dispose();
代码示例来源:origin: stackoverflow.com
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
return new Dimension(200, 200);
System.out.println("Painting has started");
int x = (int) (Math.random() * (getWidth() - 40));
int y = (int) (Math.random() * (getHeight() - 40));
Graphics2D graphics = (Graphics2D) strategy.getDrawGraphics();
graphics.setColor(Color.BLUE);
graphics.fillRect(0, 0, getWidth(), getHeight());
graphics.setColor(Color.RED);
graphics.fill(clickBounds);
} while (strategy.contentsRestored());
strategy.show();
} while (strategy.contentsLost());
代码示例来源:origin: stackoverflow.com
gt = new GameThread(this);
setFocusable(true);
addKeyListener(new KeyAdapter() {
createBufferStrategy(2);
gt.start();
requestFocusInWindow();
g2d.setColor(Color.BLACK);
g2d.fillRect(0, 0, getWidth(), getHeight());
g2d.setColor(Color.WHITE);
g2d.fillRect(player.x - 25, player.y - 25, 50, 50);
return new Dimension(400, 400);
BufferStrategy bs = view.getBufferStrategy();
do {
Graphics2D g2d = (Graphics2D) bs.getDrawGraphics();
view.paintState(g2d);
g2d.dispose();
} while (bs.contentsLost());
bs.show();
Toolkit.getDefaultToolkit().sync();
try {
代码示例来源:origin: stackoverflow.com
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
return new Dimension(200, 200);
Graphics2D g2d = (Graphics2D) g.create();
g2d.dispose();
e.printStackTrace();
addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
addMouseMotionListener(new MouseMotionListener() {
public void mouseDragged(MouseEvent e) {
Graphics g = bs.getDrawGraphics();
g.drawImage(bg, 0, 0, getWidth(), getHeight(), null);
FontMetrics fm = g.getFontMetrics();
g.setColor(Color.RED);
g.drawString(String.valueOf(averageFPS), 0, fm.getAscent());
g.dispose();
bs.show();
tick();
代码示例来源:origin: stackoverflow.com
Dimension size = new Dimension(WIDTH, HEIGHT);
setPreferredSize(size);
frame = new JFrame();
Graphics g = bs.getDrawGraphics();
g.setColor(Color.BLACK);
g.fillOval(0, 0, 20, 20);
g.dispose();
bs.show();
myPanel.frame.add(myPanel);
myPanel.frame.pack();
myPanel.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myPanel.frame.setLocationRelativeTo(null);
myPanel.frame.setVisible(true);
代码示例来源:origin: stackoverflow.com
public static JFrame frame = new JFrame("EmiloLadderSnack v. 1.0");
public static int width = Toolkit.getDefaultToolkit().getScreenSize().width, height = Toolkit.getDefaultToolkit().getScreenSize().height;
public boolean run = false;
Graphics g = bs.getDrawGraphics();
g.drawImage(img, 0, 0, width, height, null);
g.dispose();
bs.show();
LadderSnack ladderSnack = new LadderSnack();
frame.setSize(width, height);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.add(ladderSnack);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
代码示例来源:origin: stackoverflow.com
public static JFrame frame = new JFrame();
public static Thread gameThread = new Thread();
Graphics g = bs.getDrawGraphics();
g.fillRect(0, 0, WIDTH * SCALE, HEIGHT * SCALE);// change the size
g.dispose();
bs.show();
main.setPreferredSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
main.setMaximumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
main.setMinimumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
frame.add(main);// add the main(canvas).
frame.setTitle(title);
frame.setSize(WIDTH * SCALE, HEIGHT * SCALE);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
代码示例来源:origin: stackoverflow.com
canvas.setPreferredSize(new Dimension(200, 200));
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setIgnoreRepaint(true);
frame.add(canvas);
frame.pack();
while (true) {
BufferStrategy bs = canvas.getBufferStrategy();
Graphics2D g2d = (Graphics2D) bs.getDrawGraphics();
g2d.setColor(Color.RED);
g2d.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
g2d.drawString("Frame Size = " + w.getWidth() + "x" + w.getHeight(), 0, (fm.getHeight()) + fm.getAscent());
bs.show();
代码示例来源:origin: stackoverflow.com
JTextField tf = new JTextField(30);
JPanel jp = new JPanel();
JFrame jf = new JFrame();
int frames = 0;
int updates = 0;
requestFocus();
int B= (int)(Math.random( )*256);
Color randomColor = new Color(R, G, B);
Graphics g = bs.getDrawGraphics();
g.drawString("Arvaa sana", 100 , 100);
g.setColor(Color.white);
g.fillRect(0, 50, leveys, korkeus);
g.setColor(randomColor);
g.setFont(h);
g.dispose();
bs.show();
代码示例来源:origin: stackoverflow.com
setIgnoreRepaint(true);
t.start();
if(!bufferStrategy.contentsLost())
bufferStrategy.show();
g.setColor(g.getBackground());
g.fillRect(0,0,getWidth(),getHeight());
return (Graphics2D)bufferStrategy.getDrawGraphics();
drawArea.setSize(new Dimension(getWidth(),getHeight()));
add(drawArea);
createBufferStrategy(2);
bufferStrategy = drawArea.getBufferStrategy();
g.dispose();
内容来源于网络,如有侵权,请联系作者删除!