import java.awt.Graphics;
import javax.swing.JPanel;public class ConcentricCircles extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);

int width = getWidth();
int height = getHeight();
int x = 0;
int y = 0;
for (int i=0; i<10; i++)
{
g.drawArc(x, y, width, height, 0, 360);
x += 10;
y += 10;
width -= 10;
height -= 10;
}
}
}
我的目的是画十个同心圆,并且把显示的窗口调成了正方形了,可是显示出来的不是同心圆,请大家帮帮忙,谢谢!

解决方案 »

  1.   

    import java.awt.Graphics;
    import javax.swing.JPanel;public class ConcentricCircles extends JPanel {
    public void paintComponent(Graphics g) {
    super.paintComponent(g); int width = getWidth();
    int height = getHeight();
    int x = 0;
    int y = 0;
    for (int i = 0; i < 10; i++) {
    g.drawArc(x, y, width, height, 0, 360);
    x += 10;
    y += 10;
    width -= 20;
    height -= 20;
    }
    }
    }