【发布时间】:2012-08-17 04:59:27
【问题描述】:
我正在尝试在 OS X 中创建一个简单的 JFrame 窗口并在其上渲染一个简单的黑色方块,就像使用 Graphics2d 一样:
public Start() {
running = true;
window = new JFrame("Finest Hour");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setPreferredSize(new Dimension(500, 500));
window.setSize(window.getPreferredSize());
FullScreenUtilities.setWindowCanFullScreen(window, true);
window.setIgnoreRepaint(true);
window.setVisible(true);
window.createBufferStrategy(2);
strategy = window.getBufferStrategy();
}
public static void main(String[] args) {
Start s = new Start();
s.loop();
}
public void loop() {
Random random = new Random();
while(running) {
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
g.setColor(Color.black);
g.fillRect(20, 20, 40, 40);
strategy.show();
}
}
但是,当我使用 strategy.show(); 时,窗口底部似乎没有圆角; :
在没有缓冲策略的情况下渲染它,即:Graphics2D = (Graphics2D) window.getGraphics();产生一个圆角的窗口:
我知道这是一个非常小的问题,但它仍然很烦人。有什么办法解决这个问题?
【问题讨论】:
-
我建议在 Swing 的 EDT 中编写 GUI 相关代码:docs.oracle.com/javase/tutorial/uiswing/concurrency/…
-
@SoboLAN 它实际上是用于游戏动画的,但无论如何我都很想知道这是什么原因。
标签: java macos swing graphics graphics2d