【发布时间】:2016-01-09 02:45:44
【问题描述】:
public void configure() {
Frame frame = ctx.getFrame();
frame.setTitle("AstroCycles | By: Carlos Aviles");
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setFocusable(true);
frame.setSize(WIDTH, HEIGHT);
frame.addKeyListener(ctx.getKeyEventDispatcher());
frame.addWindowListener(ctx.getWindowEventDispatcher());
frame.addMouseListener(ctx.getMouseEventDispatcher());
frame.setVisible(true);
frame.createBufferStrategy(3);
frame.getBufferStrategy().getDrawGraphics().setColor(Color.RED);
frame.getBufferStrategy().getDrawGraphics().fillRect(0, 0, 75, 75);
frame.getBufferStrategy().getDrawGraphics().dispose();
frame.getBufferStrategy().show();
}
框架正在显示,但具有请求坐标和大小的矩形(红色)未显示在框架上。我不知道为什么它不画。控制台没有抛出任何错误。 BufferStrategy 也不为空。
【问题讨论】:
-
getDrawGraphics每次都会返回一个新缓冲区,因此您首先在一个缓冲区上setColor,在另一个缓冲区上fillRect然后在另一个缓冲区上show... -
我不知道。谢谢。