Problem mit BufferStrategy

Venek

Mitglied
Hallo,

ich habe da ein Problem mit BufferStrategy.

Exception:

Code:
Exception in thread "main" java.lang.IllegalStateException: Buffers have not been created
    at sun.awt.X11.XComponentPeer.getBackBuffer(XComponentPeer.java:1202)
    at java.awt.Component$FlipBufferStrategy.getBackBuffer(Component.java:4067)
    at java.awt.Component$FlipBufferStrategy.flip(Component.java:4087)
    at java.awt.Component$FlipBufferStrategy.show(Component.java:4215)
    at pong.game.Window.draw(Window.java:34)
    at pong.game.Main.main(Main.java:19)

Window.java

Java:
package pong.game;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferStrategy;

public class Window extends JFrame {
  
    private BufferStrategy buff_strat;
  
    public Window(String title) {
        super(title);
      
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(800, 600);
        this.setLocationRelativeTo(null);
        this.setResizable(false);
        this.setVisible(true);
      
        this.getContentPane().setBackground(Color.BLACK);
      
        this.createBufferStrategy(2);
        buff_strat = this.getBufferStrategy();
    }
  
    public void update() {
      
    }
  
    public void draw() {
        Graphics2D g = (Graphics2D) buff_strat.getDrawGraphics();
      
        buff_strat.dispose();
        buff_strat.show();
    }
}

Meine Frage ist, warum wirft er die Exception ich verstehe das nicht es hat doch sonst auch immer funktioniert.

MfG Venek
 
Ich vermute du darfst nicht dispose() aufrufen, da du die Bufferstragy ja später noch verwenden möchtest.
Vielleicht wolltest du dispose auf dem Grahics-Objekt aufrufen?
 

Neue Themen


Zurück
Oben