我有一個java程序,它在屏幕上顯示一個橢圓,並通過使用箭頭鍵來改變它的方向。我經常使用while循環在橢圓上調用repaint()。在Java中繪畫橢圓
橢圓移動,但問題是它的路徑上留下了一個省略號。我如何製作它,以便刪除舊的省略號,然後重新繪製新的省略號?
代碼:
public void run(){
while (animator != null)
{
setBackground(Color.GREEN);
repaint();
// The direction works and the rest works fine.
player1.move(player1, player1.direction);
try
{
Thread.sleep(100);
}
catch (InterruptedException e)
{
break;
}
}
}
// The paintComponent of my player1 is fine.
public void paint(Graphics g){
Graphics2D g2 = (Graphics2D)g;
player1.paintComponent(g2, player1);
}