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){}

    }

}

}


ITMISS
浏览 212回答 3
3回答

慕虎7371278

循环完成后,它不会被清除。

德玛西亚99

您在设置弧线后设置前景,因此,它被写过。这就是为什么你看不到任何东西。

ibeautiful

为了保持油漆,遵循阿比纳夫的想法。但是要更改颜色,请参阅下面的代码:(一切都不是固定的,但您可以从这个想法开始)public class ColorArcs extends Applet{int width=50;int length=50;int topx=200-25,topy=200-25;public void paint(Graphics g){&nbsp; &nbsp; for(;length<250;)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; length+=2;&nbsp; &nbsp; &nbsp; &nbsp; width++;&nbsp; &nbsp; &nbsp; &nbsp; if(length>=50&&length<=75)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setForeground(Color.cyan);&nbsp; &nbsp; }&nbsp; &nbsp; int length_ = 50; width=50;&nbsp; &nbsp; for(;length_<250;)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; g.drawArc(200-length_/2,200-width/2,length_,width,0,180);&nbsp; &nbsp; &nbsp; &nbsp; length_+=2;&nbsp; &nbsp; &nbsp; &nbsp; width++;&nbsp; &nbsp; &nbsp; &nbsp; try&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Thread.sleep(20);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; catch(InterruptedException ie){}&nbsp; &nbsp; }}}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java