首先,我知道這樣的問題已經被問過,但沒有答案似乎解決了我的問題。組件必須有一個有效的對等體 - BufferStrategy
我正在開發一個小遊戲,並且由於某種原因,每當我嘗試創建新的bufferstrategy時,java都會返回IllegalStateException。我加入遊戲一個JFrame,但是例外還是拋出,這裏是添加到JFrame代碼:
JFrame frame;
public Window(int x, int y, int width, int height, String title, boolean focus, Main game) throws IOException {
frame = new JFrame();
frame.setLocation(x, y);
frame.setSize(new Dimension(width, height));
frame.setTitle(title);
frame.add(game);
game.start();
frame.setAutoRequestFocus(focus);
frame.setFocusable(true);
frame.setVisible(true);
}
,這裏是用於創建窗口(位於主類)的代碼:
window = new Window(x, y, WIDTH, HEIGHT, "Title", true, this);
在'frame.setVisible(true)之後放置'game.start();'改變什麼? – Berger
@Berger是的,謝謝! – ItzBenteThePig