【发布时间】:2016-09-15 05:17:03
【问题描述】:
首先,我知道以前有人问过这样的问题,但似乎没有答案可以解决我的问题。
我正在开发一个小游戏,由于某种原因,每当我尝试创建新的缓冲区策略时,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);
}
下面是创建窗口的代码(位于 Main 类中):
window = new Window(x, y, WIDTH, HEIGHT, "Title", true, this);
【问题讨论】:
-
将
game.start();放在frame.setVisible(true);之后会改变什么吗? -
@Berger 是的,谢谢!
标签: java swing bufferstrategy