我想创建12个同心圆,其中第一个是半径10像素,其余的是不同的颜色。我坚持如何改变半径,我认为让它们变得不同颜色很容易。我目前输出12个非常小的圆圈。我不确定是什么问题。
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
public class Circles extends JComponent {
public void paintComponent(Graphics g){
int width = getWidth();
int height = getHeight();
int xPoint = width / 2;
int yPoint = height / 2;
for(int i = 5; i <= 12; i++){
g.drawOval(xPoint - (i * 5), yPoint - (i * 5), (i * 10), (i * 10));
}
}
@Override
public Dimension getPreferredSize(){
return new Dimension(400, 400);
}
public static void main(String[] args){
JFrame frame = new JFrame("Line Loop");
frame.add(new Circles());
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
答案 0 :(得分:0)
for(int i = 0; i <= 12; i++){
g.drawOval(xPoint - (i * 50), yPoint - (i * 50), (i * 100), (i * 100));
}
}