I am getting an error saying that it cannot make a static reference to a non-static for the BufferStrategy...
package main;
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;
public class Game extends Canvas implements Runnable{
private static final long serialVersionUID = 1L;
public static int width = 300;
public static int height = width / 16 * 9;
public static int scale = 3;
public boolean isRunning = false;
private Thread gameT;
private JFrame frame;
public synchronized void start(){
isRunning = true;
gameT = new Thread(this);
gameT.start();
}
public synchronized void stop(){
isRunning = false;
try{
gameT.join();
}catch(InterruptedException e ){
e.getStackTrace();
}
}
public Game(){
Dimension resolution = new Dimension(width * scale, height * scale);
setPreferredSize(resolution);
frame = new JFrame();
}
public static void main(String[] args){
Game game = new Game();
game.frame.setVisible(true);
game.frame.setResizable(false);
game.frame.setTitle("GameTest");
game.frame.add(game);
game.frame.pack();
game.frame.setLocationRelativeTo(null);
game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
game.start();
}
@Override
public void run() {
update();
render();
}
public static void update(){
}
public static void render(){
BufferStrategy bs = getBufferStrategy();
if(bs == null){
createBufferStrategy(3);
return;
}
}
}
Now i don't know how to get over it because is from the Canvas class, and i tried to make it a static object but it doesn't work either.