[英]Make JFrame not repaint
im trying not to repaint my window in Java. 我试图不重画我在Java中的窗口。 I have:
我有:
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
ball.paint(g2d);
}
and in main: 主要:
while (true) {
game.move();
game.repaint();
Thread.sleep(10);
}
my JFrame is window and I have tried window.setIgnoreRepaint(true);
我的JFrame是window,我已经尝试过
window.setIgnoreRepaint(true);
but there was no change. 但没有变化。 Could you give me a hand?
你能帮我一下吗? Thank you :)
谢谢 :)
while (true) {
game.move();
game.repaint();
Thread.sleep(10);
}
must be replaced with 必须替换为
Timer t=new Timer(10,new ActionListener() {
public void actionPerformed(ActionEvent e) {
game.move();
game.repaint();
}
});
t.start();
And override paintComponent() of content pane. 并覆盖内容窗格的paintComponent()。
super.paint(g)
repaints the window - you need to remove this line. 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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.