OK i reading something about Your solution at http://www.cokeandcode.com/ and i trying to put some code to my own project, can You check if i good thinking about it or if i go to good way.
package dbtest;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class DBTest extends Canvas{
private BufferStrategy strategy;
private boolean gameRunning = true;
private JFrame container;
private int screenWidth = 1024;
private int screenHeight = 764;
private int x = 1;
public DBTest()
{
container = new JFrame("Space Invaders 101");
JPanel panel = (JPanel) container.getContentPane();
panel.setPreferredSize(new Dimension(screenWidth,screenHeight));
panel.setLayout(null);
setBounds(0,0,screenWidth,screenHeight);
panel.add(this);
setIgnoreRepaint(true);
container.pack();
container.setResizable(false);
container.setVisible(true);
container.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
requestFocus();
createBufferStrategy(2);
strategy = getBufferStrategy();
}
public void gameLoop() {
long lastLoopTime = System.currentTimeMillis();
while (gameRunning) {
long delta = System.currentTimeMillis() - lastLoopTime;
lastLoopTime = System.currentTimeMillis();
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
g.setColor(Color.black);
g.fillRect(0,0,screenWidth,screenHeight);
update();
paint(g);
g.dispose();
strategy.show();
try { Thread.sleep(10); } catch (Exception e) {}
}
}
public void update()
{
x++;
}
public void paint(Graphics2D g)
{
g.setColor(Color.white);
g.fillOval(x, getHeight() / 2, 100 , 100);
}
public static void main(String[] args){
DBTest game = new DBTest();
game.gameLoop();
}
}
in Paint method i test “Oval” to smooth move to the right side of screen. Method isDoubleBuffered still say “false” in System Log but meybe i put that check in wrong place.
Thanks you for Your help, friend.