当程序运行时,我需要在不同的位置不断地重绘某个图像。所以我设置了一个while循环,它应该在屏幕上移动图像,但它只是一遍又一遍地重绘图像。我究竟做错了什么?有没有办法在将旧图像绘制到新位置之前删除它?
JFrame frame = buildFrame();
final BufferedImage image = ImageIO.read(new File("BeachRoad_double_size.png"));
JPanel pane = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int num = 0;
boolean fluff = true;
while (fluff == true) {
num = num + 1;
g.drawImage(image, num, 0, null);
if (num == 105) {
fluff = false;
}
}
}
};
frame.add(pane);