下面是一個簡單的小程序代碼,問題出在 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){} }}}
3 回答

ibeautiful
TA貢獻1993條經驗 獲得超6個贊
為了保持油漆,遵循阿比納夫的想法。但是要更改顏色,請參閱下面的代碼:(一切都不是固定的,但您可以從這個想法開始)
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){}
}
}
}
添加回答
舉報
0/150
提交
取消