我试图不用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);
,但没有任何变化。你能帮我个忙吗?谢谢:))
答案 0 :(得分:2)
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();
并覆盖内容窗格的paintComponent()。
答案 1 :(得分:-1)
super.paint(g)
重新绘制窗口 - 您需要删除此行。
public void paint(Graphics g) {
// super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
ball.paint(g2d);
}