2014-02-27 105 views
0

到目前爲止,這是我以前的代碼,我以前用相同的代碼創建了一個100循環的循環,但現在我需要使用while語句,只是有點困惑什麼整數使用和不使用。我編譯它沒有任何錯誤,但是當它運行時,窗口彈出並沒有任何內容....雖然循環繪圖圈

public void paintComponent(Graphics g) { 
super.paintComponent(g); 

Dimension d = getSize(); 
{ 
int i = 0; 
while (i<=100)       
{  
    Color color = new Color(generator.nextInt(255), 
     generator.nextInt(255), generator.nextInt(255)); 
    g.setColor(color); 

    int circleSize = generator.nextInt(d.width/4); 
    int x = generator.nextInt(d.width - circleSize); 
    int y = generator.nextInt(d.height - circleSize); 
    g.fillOval(x, y, circleSize, circleSize); 
    g.drawArc(x, y, circleSize, circleSize, 0, 360); 
    } 
} 
+1

你忘了在while循環中增加'i' – donfuxx

+0

另外,要確保你保持在邊界內。 – Brian

回答

4

你處於無限循環。你並沒有增加i。將i++;添加到循環的底部,循環應該至少終止。

+1

我從字面上只是看到了......謝謝你,雖然現在可行,但我知道我忘記了一些東西。 –

+0

@ZekeP無後顧之憂;我們都被這個bug困住了很多次:) –