我试图不用 Java 重新绘制我的窗口。我有:
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
ball.paint(g2d);
}
并且在主要部分:
while (true) {
game.move();
game.repaint();
Thread.sleep(10);
}
我的 JFrame 是窗口,我尝试过 window.setIgnoreRepaint(true);
但没有任何变化。你能帮我一下吗?谢谢:)
最佳答案
while (true) {
game.move();
game.repaint();
Thread.sleep(10);
}
必须替换为
Timer t=new Timer(10,new ActionListener() {
public void actionPerformed(ActionEvent e) {
game.move();
game.repaint();
}
});
t.start();
并覆盖内容 Pane 的paintComponent()。
关于java - 使 JFrame 不重绘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23055835/