Zkusil jsme udělat jednoduchý program, ale nefungoval. Chyba se nejspíš bude vyskytovat ve vytvoření grafiky v metodě render().
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
public class main extends Canvas {
public static final int WIDTH=320;
public static final int HEIGHT=WIDTH/16*9;
public static final int SCALE=2;
private BufferedImage image=new BufferedImage(HEIGHT, WIDTH, BufferedImage.TYPE_INT_RGB);
public static void main(String[] args) {
main main=new main();
main.setPreferredSize(new Dimension(WIDTH*SCALE, HEIGHT*SCALE));
main.setMaximumSize(new Dimension(WIDTH*SCALE, HEIGHT*SCALE));
main.setMinimumSize(new Dimension(WIDTH*SCALE, HEIGHT*SCALE));
JFrame frame=new JFrame("pokus");
frame.add(main);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
main.render();
}
private void render(){
BufferStrategy bs=this.getBufferStrategy();
if(bs==null){
createBufferStrategy(3);
return;
}
Graphics g=bs.getDrawGraphics();
/////////////////////////////////////////////
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
/////////////////////////////////////////////
g.dispose();
bs.show();
}
}