2014-02-26 11 views
-1

關於圓的圓周的問題。爲了改變圓(周長)的色彩外,我會用使用arcAngle着色圓的外側

drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) 

只是不正是如何將下面的代碼below..after Public void drawArc我不知道以後開始去哪裏

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

    Dimension d = getSize(); 

    for(int i = 0; i < 100; ++i) {       
     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

您是否有可能誤解您的任務?我認爲你的老師希望你使用'Graphics'類的'drawArc'方法,而不是寫你自己的。 –

+0

@DavidWallace我同意,這是我改變了它,但現在我又被卡住了.. –

+0

@DavidWallace添加聲明來改變顏色做了工作謝謝! –

回答

0

你不需要你自己的drawArc方法,你應該調用Graphics.drawArc()方法。 xy是圓的中心,widthheight是圓的直徑,並且startAnglearcAngle是開始和停止繪製圓的地方。 0是3點。所以要繪製一個完整的圓,你可以使用0和360代替startAnglearcAngle

1

您正在繪製一個圓的正文,然後繪製其輪廓,而不會改變它們之間的顏色。這意味着你實際上看不到圓圈的輪廓。

我想你應該在繪製輪廓之前更改圖形上下文的顏色。一種方法是調用drawArc之前插入

color = new Color(generator.nextInt(255), generator.nextInt(255), generator.nextInt(255)); 
g.setColor(color);