for 循环结束后,为什么小程序屏幕上没有任何显示?

After the for loop is finished why nothing is displayed in the applet screen?

下面是一个简单的 Applet 代码,问题出在 for 循环完成后。

小程序屏幕上没有任何显示。

我猜屏幕在 for 循环结束后被清除了。

我无法修复它我想知道如何防止屏幕被清除,以便我的输出显示在屏幕上。

public class ColorArcs extends Applet
{
int width=50;
int length=50;

int topx=200-25,topy=200-25;

public void paint(Graphics g)
{
    for(;length<250;)
    {
        g.drawArc(200-length/2,200-width/2,length,width,0,180);

        length+=2;
        width++;

        if(length>=50&&length<=75)
            setForeground(Color.cyan);
        else
            if(length>=75&&length<=100)
            setForeground(Color.yellow);
        else
            if(length>=100&&length<=125)
            setForeground(Color.green);
        else
            setForeground(Color.red);

        try
        {
            Thread.sleep(80);
        }
        catch(InterruptedException ie){}
    }
}
}

设置弧线后设置前景,因此被覆盖。这就是为什么你看不到任何东西的原因。

for循环结束后没有清除。

按照 Abhinav 的想法维护油漆。但是要更改颜色,请参阅下面的代码:(一切都不是固定的,但你可以从这个想法开始)

public class ColorArcs extends Applet
{
int width=50;
int length=50;

int topx=200-25,topy=200-25;

public void paint(Graphics g)
{
    for(;length<250;)
    {
        length+=2;
        width++;

        if(length>=50&&length<=75)
            setForeground(Color.cyan);

    }

    int length_ = 50; width=50;
    for(;length_<250;)
    {
        g.drawArc(200-length_/2,200-width/2,length_,width,0,180);

        length_+=2;
        width++;

        try
        {
            Thread.sleep(20);
        }
        catch(InterruptedException ie){}
    }
}
}