我的绘画方法是这样的。

public void paint (Graphics g)
{

    while (cardChosen != 'a');
    {
       g.drawImage (selectionBG, 0, 0, 1960, 677, null);
        g.drawImage (duelSGX, x_coordinate, y_coordinate, 483, 677, null);
        g.drawImage (Ultor, x_coordinate + 777, y_coordinate, 483, 677, null);
        g.drawImage (Seirin, x_coordinate + 777 * 2, y_coordinate, 483, 677, null);
        g.drawImage (Rowgen, x_coordinate + 777 * 3, y_coordinate, 483, 677, null);
        g.drawImage (Ronel, x_coordinate + 777 * 4, y_coordinate, 483, 677, null);
        g.drawImage (Ophelia, x_coordinate + 777 * 5, y_coordinate, 483, 677, null);
        g.drawImage (Narza, x_coordinate + 777 * 6, y_coordinate, 483, 677, null);
        g.drawImage (Michele, x_coordinate + 777 * 7, y_coordinate, 483, 677, null);
        g.drawImage (Maxwell, x_coordinate + 777 * 8, y_coordinate, 483, 677, null);
        g.drawImage (MageDEAN, x_coordinate + 777 * 9, y_coordinate, 483, 677, null);
        g.drawImage (Kuda, x_coordinate + 777 * 10, y_coordinate, 483, 677, null);
        g.drawImage (Gravion, x_coordinate + 777 * 11, y_coordinate, 483, 677, null);
    }

}


我也有这个

    if (ev.getKeyCode () == KeyEvent.VK_A)
    cardChosen = 'a';

    repaint ();


现在考虑一下,当我按“ a”键时,我痛苦中描绘的所有事物难道不应该消失吗?
没有。图片显示,向上并且滞后。

最佳答案

您的paint(...)方法应为:

public void paint(Graphics g)
{
    super.paint(g); // to clear the background

    // add your code here
}

关于java - 图形g-使用油漆,如何删除东西?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27790968/

10-13 05:47